001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.weaver.utils; 020 021/** 022 * Argument/Parameter-related utilities. 023 */ 024public final class Args { 025 026 private Args() { 027 } 028 029 /** 030 * Compare two parameter type arrays. 031 * 032 * @param paramTypes1 033 * lhs 034 * @param paramTypes2 035 * rhs 036 * @return {@code int} as specified by {@link java.util.Comparator#compare(Object, Object)} 037 */ 038 @SuppressWarnings("PMD.UseVarargs") // not needed for comparing one array to another 039 public static int compare(final Class<?>[] paramTypes1, final Class<?>[] paramTypes2) { 040 for (int param = 0; param < paramTypes1.length; param++) { 041 if (param >= paramTypes2.length) { 042 return 1; 043 } 044 final int test = paramTypes1[param].getName().compareTo(paramTypes2[param].getName()); 045 if (test == 0) { 046 continue; 047 } 048 return test; 049 } 050 if (paramTypes1.length == paramTypes2.length) { 051 return 0; 052 } 053 return -1; 054 } 055 056}