KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > util > jmx > MBeanOperationInfoComparator


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.appserv.management.util.jmx;
25
26 import javax.management.MBeanOperationInfo JavaDoc;
27
28 import com.sun.appserv.management.util.jmx.stringifier.MBeanOperationInfoStringifier;
29 import com.sun.appserv.management.util.jmx.stringifier.MBeanFeatureInfoStringifierOptions;
30
31
32 /**
33     Caution: this Comparator may be inconsistent with equals() because it ignores the description.
34  */

35 public final class MBeanOperationInfoComparator
36     implements java.util.Comparator JavaDoc<MBeanOperationInfo JavaDoc>
37 {
38     private static final MBeanOperationInfoStringifier OPERATION_INFO_STRINGIFIER =
39         new MBeanOperationInfoStringifier( new MBeanFeatureInfoStringifierOptions( false, ",") );
40         
41         
42     public static final MBeanOperationInfoComparator
43         INSTANCE = new MBeanOperationInfoComparator();
44     
45     private MBeanOperationInfoComparator() {}
46     
47         public int
48     compare( final MBeanOperationInfo JavaDoc info1, final MBeanOperationInfo JavaDoc info2 )
49     {
50         final MBeanOperationInfoStringifier sf = OPERATION_INFO_STRINGIFIER;
51         
52         // we just want to sort based on name and signature; there can't be two operations with the
53
// same name and same signature, so as long as we include the name and signature the
54
// sorting will always be consistent.
55
int c = info1.getName().compareTo( info2.getName() );
56         if ( c == 0 )
57         {
58             // names the same, subsort on signature, first by number of params
59
c = info1.getSignature().length - info2.getSignature().length;
60             if ( c == 0 )
61             {
62                 // names the same, subsort on signature, first by number of params
63
c = sf.getSignature( info1 ).compareTo( sf.getSignature( info2 ) );
64             }
65             
66         }
67         
68         return( c );
69     }
70     
71         public boolean
72     equals( Object JavaDoc other )
73     {
74         return( other instanceof MBeanOperationInfoComparator );
75     }
76 }
77
78
79
80
81
Popular Tags