View Javadoc

1   /*
2   MadCaching is a Tile Caching solution
3   Copyright (C) 2005  Mac Vu
4   
5   This program is free software; you can redistribute it and/or
6   modify it under the terms of the GNU General Public License
7   as published by the Free Software Foundation; either version 2
8   of the License, or (at your option) any later version.
9   
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  package com.macvu.tiles;
20  
21  import java.util.Comparator;
22  
23  public class CacheAttributeComparator implements Comparator {
24      public int compare(Object o1, Object o2) {
25          CacheAttribute attribute1 = (CacheAttribute) o1;
26          CacheAttribute attribute2 = (CacheAttribute) o2;
27  
28          int a1ScopeIndex = getOrderIndex(attribute1.getScope());
29          int a2ScopeIndex = getOrderIndex(attribute2.getScope());
30  
31          if (a1ScopeIndex == a2ScopeIndex) {
32              return attribute1.getName().compareToIgnoreCase(attribute2.getName());
33          } else {
34              return a1ScopeIndex - a2ScopeIndex;
35          }
36      }
37  
38      protected int getOrderIndex(String scope) {
39          int orderIndex = -1;
40          boolean found = false;
41          for (int i = 0; !found && i < CacheAttribute.scope_order.length; i++) {
42              if (CacheAttribute.scope_order[i].equalsIgnoreCase(scope)) {
43                  orderIndex = i;
44                  found = true;
45              }
46          }
47  
48          return orderIndex;
49      }
50  }