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