1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.documentlibrary.util.comparator;
16  
17  import com.liferay.portal.kernel.util.OrderByComparator;
18  import com.liferay.portlet.documentlibrary.model.DLFileVersion;
19  
20  /**
21   * <a href="FileVersionVersionComparator.java.html"><b><i>View Source</i></b>
22   * </a>
23   *
24   * @author Bruno Farache
25   */
26  public class FileVersionVersionComparator extends OrderByComparator {
27  
28      public static String ORDER_BY_ASC = "version ASC";
29  
30      public static String ORDER_BY_DESC = "version DESC";
31  
32      public static String[] ORDER_BY_FIELDS = {"version"};
33  
34      public FileVersionVersionComparator() {
35          this(false);
36      }
37  
38      public FileVersionVersionComparator(boolean asc) {
39          _asc = asc;
40      }
41  
42      public int compare(Object obj1, Object obj2) {
43          DLFileVersion fileVersion1 = (DLFileVersion)obj1;
44          DLFileVersion fileVersion2 = (DLFileVersion)obj2;
45  
46          int value = 0;
47  
48          if (fileVersion1.getVersion() < fileVersion2.getVersion()) {
49              value = -1;
50          }
51          else if (fileVersion1.getVersion() > fileVersion2.getVersion()) {
52              value = 1;
53          }
54  
55          if (_asc) {
56              return value;
57          }
58          else {
59              return -value;
60          }
61      }
62  
63      public String getOrderBy() {
64          if (_asc) {
65              return ORDER_BY_ASC;
66          }
67          else {
68              return ORDER_BY_DESC;
69          }
70      }
71  
72      public String[] getOrderByFields() {
73          return ORDER_BY_FIELDS;
74      }
75  
76      public boolean isAscending() {
77          return _asc;
78      }
79  
80      private boolean _asc;
81  
82  }