01: /*
02: * Distributed as part of c3p0 v.0.9.1.2
03: *
04: * Copyright (C) 2005 Machinery For Change, Inc.
05: *
06: * Author: Steve Waldman <swaldman@mchange.com>
07: *
08: * This library is free software; you can redistribute it and/or modify
09: * it under the terms of the GNU Lesser General Public License version 2.1, as
10: * published by the Free Software Foundation.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public License
18: * along with this software; see the file LICENSE. If not, write to the
19: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: */
22:
23: package com.mchange.v2.management;
24:
25: import javax.management.*;
26: import java.util.Comparator;
27:
28: public class ManagementUtils {
29: public final static Comparator PARAM_INFO_COMPARATOR = new Comparator() {
30: public int compare(Object a, Object b) {
31: MBeanParameterInfo aa = (MBeanParameterInfo) a;
32: MBeanParameterInfo bb = (MBeanParameterInfo) b;
33: int out = aa.getType().compareTo(bb.getType());
34: if (out == 0) {
35: out = aa.getName().compareTo(bb.getName());
36: if (out == 0) {
37: String aDesc = aa.getDescription();
38: String bDesc = bb.getDescription();
39: if (aDesc == null && bDesc == null)
40: out = 0;
41: else if (aDesc == null)
42: out = -1;
43: else if (bDesc == null)
44: out = 1;
45: else
46: out = aDesc.compareTo(bDesc);
47: }
48: }
49: return out;
50: }
51: };
52:
53: public final static Comparator OP_INFO_COMPARATOR = new Comparator() {
54: public int compare(Object a, Object b) {
55: MBeanOperationInfo aa = (MBeanOperationInfo) a;
56: MBeanOperationInfo bb = (MBeanOperationInfo) b;
57: String aName = aa.getName();
58: String bName = bb.getName();
59: int out = String.CASE_INSENSITIVE_ORDER.compare(aName,
60: bName);
61: if (out == 0) {
62: if (aName.equals(bName)) {
63: MBeanParameterInfo[] aParams = aa.getSignature();
64: MBeanParameterInfo[] bParams = bb.getSignature();
65: if (aParams.length < bParams.length)
66: out = -1;
67: else if (aParams.length > bParams.length)
68: out = 1;
69: else {
70: for (int i = 0, len = aParams.length; i < len; ++i) {
71: out = PARAM_INFO_COMPARATOR.compare(
72: aParams[i], bParams[i]);
73: if (out != 0)
74: break;
75: }
76: }
77: } else {
78: out = aName.compareTo(bName);
79: }
80: }
81: return out;
82: }
83: };
84: }
|