1 17 18 package org.apache.geronimo.console.web.util; 19 20 import java.util.Comparator ; 21 import java.util.StringTokenizer ; 22 import javax.management.ObjectInstance ; 23 import javax.management.ObjectName ; 24 25 30 31 public class MBeanComparator implements Comparator { 32 private static final int LEFT_GREATER = 1; 33 private static final int RIGHT_GREATER = -1; 34 private static final int EQUAL = 0; 35 36 public int compare(Object o1, Object o2) { 37 38 ObjectName left = ((ObjectInstance ) o1).getObjectName(); 39 ObjectName right = ((ObjectInstance ) o2).getObjectName(); 40 String leftName = left.getCanonicalName(); 41 String rightName = right.getCanonicalName(); 42 43 StringTokenizer leftDomainTokenizer = 44 new StringTokenizer (leftName, "."); 45 46 StringTokenizer rightDomainTokenizer = 47 new StringTokenizer (rightName, "."); 48 49 while (leftDomainTokenizer.hasMoreTokens()) { 50 if (!rightDomainTokenizer.hasMoreTokens()) { 51 return RIGHT_GREATER; 52 } 53 String leftToken = leftDomainTokenizer.nextToken(); 54 String rightToken = rightDomainTokenizer.nextToken(); 55 int comparison = leftToken.compareToIgnoreCase(rightToken); 56 if (comparison != 0) { 57 return comparison; 58 } 59 } 60 61 if (rightDomainTokenizer.hasMoreTokens()) { 63 return LEFT_GREATER; 64 } 65 return EQUAL; 67 } 68 } 69 | Popular Tags |