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.DateUtil;
18  import com.liferay.portal.kernel.util.OrderByComparator;
19  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
20  
21  /**
22   * <a href="FileEntryModifiedDateComparator.java.html"><b><i>View Source</i></b>
23   * </a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class FileEntryModifiedDateComparator extends OrderByComparator {
28  
29      public static String ORDER_BY_ASC = "modifiedDate ASC";
30  
31      public static String ORDER_BY_DESC = "modifiedDate DESC";
32  
33      public static String[] ORDER_BY_FIELDS = {"modifiedDate"};
34  
35      public FileEntryModifiedDateComparator() {
36          this(false);
37      }
38  
39      public FileEntryModifiedDateComparator(boolean asc) {
40          _asc = asc;
41      }
42  
43      public int compare(Object obj1, Object obj2) {
44          DLFileEntry fileEntry1 = (DLFileEntry)obj1;
45          DLFileEntry fileEntry2 = (DLFileEntry)obj2;
46  
47          int value = DateUtil.compareTo(
48              fileEntry1.getModifiedDate(), fileEntry2.getModifiedDate());
49  
50          if (_asc) {
51              return value;
52          }
53          else {
54              return -value;
55          }
56      }
57  
58      public String getOrderBy() {
59          if (_asc) {
60              return ORDER_BY_ASC;
61          }
62          else {
63              return ORDER_BY_DESC;
64          }
65      }
66  
67      public String[] getOrderByFields() {
68          return ORDER_BY_FIELDS;
69      }
70  
71      public boolean isAscending() {
72          return _asc;
73      }
74  
75      private boolean _asc;
76  
77  }