1 22 23 24 package com.mchange.v2.management; 25 26 import javax.management.*; 27 import java.util.Comparator ; 28 29 public class ManagementUtils 30 { 31 public final static Comparator PARAM_INFO_COMPARATOR = new Comparator () 32 { 33 public int compare(Object a, Object b) 34 { 35 MBeanParameterInfo aa = (MBeanParameterInfo) a; 36 MBeanParameterInfo bb = (MBeanParameterInfo) b; 37 int out = aa.getType().compareTo(bb.getType()); 38 if (out == 0) 39 { 40 out = aa.getName().compareTo(bb.getName()); 41 if (out == 0) 42 { 43 String aDesc = aa.getDescription(); 44 String bDesc = bb.getDescription(); 45 if (aDesc == null && bDesc == null) 46 out = 0; 47 else if (aDesc == null) 48 out = -1; 49 else if (bDesc == null) 50 out = 1; 51 else 52 out = aDesc.compareTo(bDesc); 53 } 54 } 55 return out; 56 } 57 }; 58 59 public final static Comparator OP_INFO_COMPARATOR = new Comparator () 60 { 61 public int compare(Object a, Object b) 62 { 63 MBeanOperationInfo aa = (MBeanOperationInfo) a; 64 MBeanOperationInfo bb = (MBeanOperationInfo) b; 65 String aName = aa.getName(); 66 String bName = bb.getName(); 67 int out = String.CASE_INSENSITIVE_ORDER.compare(aName, bName); 68 if (out == 0) 69 { 70 if (aName.equals(bName)) 71 { 72 MBeanParameterInfo[] aParams = aa.getSignature(); 73 MBeanParameterInfo[] bParams = bb.getSignature(); 74 if (aParams.length < bParams.length) 75 out = -1; 76 else if (aParams.length > bParams.length) 77 out = 1; 78 else 79 { 80 for (int i = 0, len = aParams.length; i < len; ++i) 81 { 82 out = PARAM_INFO_COMPARATOR.compare(aParams[i], bParams[i]); 83 if (out != 0) 84 break; 85 } 86 } 87 } 88 else 89 { 90 out = aName.compareTo(bName); 91 } 92 } 93 return out; 94 } 95 }; 96 } 97 | Popular Tags |