1 22 23 29 30 package org.jboss.repository.plugins.basic; 31 32 import java.util.Comparator ; 33 import java.util.HashMap ; 34 35 import org.jboss.repository.spi.CommonNames; 36 37 41 public class BasicAttributeComparator 42 implements Comparator 43 { 44 private static String [] BASIC_ORDERING = { 45 CommonNames.THREAD, 46 CommonNames.REQUEST, 47 CommonNames.SESSION, 48 CommonNames.DEPLOYMENT, 49 CommonNames.APPLICATION, 50 CommonNames.SERVER, 51 CommonNames.CLUSTER, 52 CommonNames.DOMAIN 53 }; 54 private static HashMap BASIC_ORDER_INDEXES = new HashMap (); 55 static 56 { 57 for(int n = 0; n < BASIC_ORDERING.length; n ++) 58 BASIC_ORDER_INDEXES.put(BASIC_ORDERING[n], new Integer (n)); 59 } 60 61 public int compare(Object obj1, Object obj2) 62 { 63 String name1 = (String ) obj1; 64 String name2 = (String ) obj2; 65 Integer index1 = (Integer ) BASIC_ORDER_INDEXES.get(name1); 66 Integer index2 = (Integer ) BASIC_ORDER_INDEXES.get(name2); 67 int compare = 0; 68 if( index1 != null ) 69 { 70 if( index2 != null ) 71 compare = index1.compareTo(index2); 72 else 73 compare = -1; 74 } 75 else if( index2 != null ) 76 { 77 compare = 1; 79 } 80 else 81 { 82 compare = name1.compareTo(name2); 84 } 85 return compare; 86 } 87 88 } 89 | Popular Tags |