1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }