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     * @param paramTypes1 lhs
032     * @param paramTypes2 rhs
033     * @return {@code int} as specified by
034     *         {@link java.util.Comparator#compare(Object, Object)}
035     */
036    public static int compare(final Class<?>[] paramTypes1, final Class<?>[] paramTypes2) {
037        final int param = 0;
038        while (param < paramTypes1.length) {
039            if (param >= paramTypes2.length) {
040                return 1;
041            }
042            final int test = paramTypes1[param].getName().compareTo(paramTypes2[param].getName());
043            if (test == 0) {
044                continue;
045            }
046            return test;
047        }
048        if (paramTypes1.length == paramTypes2.length) {
049            return 0;
050        }
051        return -1;
052    }
053
054}