01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.helpers;
19:
20: import java.lang.reflect.Method;
21: import java.util.Comparator;
22:
23: /**
24: * Sorts methods according to their name, number of parameters, and parameter
25: * types.
26: */
27: public class MethodComparator implements Comparator<Method> {
28:
29: public int compare(Method m1, Method m2) {
30:
31: int val = m1.getName().compareTo(m2.getName());
32: if (val == 0) {
33: val = m1.getParameterTypes().length
34: - m2.getParameterTypes().length;
35: if (val == 0) {
36: Class[] types1 = m1.getParameterTypes();
37: Class[] types2 = m2.getParameterTypes();
38: for (int i = 0; i < types1.length; i++) {
39: val = types1[i].getName().compareTo(
40: types2[i].getName());
41:
42: if (val != 0) {
43: break;
44: }
45: }
46: }
47: }
48: return val;
49: }
50:
51: }
|