1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.DLFileRank;
20  
21  /**
22   * <a href="FileRankCreateDateComparator.java.html"><b><i>View Source</i></b>
23   * </a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class FileRankCreateDateComparator extends OrderByComparator {
28  
29      public static String ORDER_BY_ASC = "createDate ASC";
30  
31      public static String ORDER_BY_DESC = "createDate DESC";
32  
33      public static String[] ORDER_BY_FIELDS = {"createDate"};
34  
35      public FileRankCreateDateComparator() {
36          this(false);
37      }
38  
39      public FileRankCreateDateComparator(boolean asc) {
40          _asc = asc;
41      }
42  
43      public int compare(Object obj1, Object obj2) {
44          DLFileRank fileRank1 = (DLFileRank)obj1;
45          DLFileRank fileRank2 = (DLFileRank)obj2;
46  
47          int value = DateUtil.compareTo(
48              fileRank1.getCreateDate(), fileRank2.getCreateDate());
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  }