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