001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.proxy.factory.util;
019
020 import java.lang.reflect.Method;
021 import java.util.Arrays;
022 import java.util.List;
023
024 /**
025 * A class for capturing the signature of a method (its name and parameter types).
026 *
027 * @author James Carman
028 * @since 1.0
029 */
030 public class MethodSignature
031 {
032 //----------------------------------------------------------------------------------------------------------------------
033 // Fields
034 //----------------------------------------------------------------------------------------------------------------------
035
036 private final String name;
037 private final List parameterTypes;
038
039 //----------------------------------------------------------------------------------------------------------------------
040 // Constructors
041 //----------------------------------------------------------------------------------------------------------------------
042
043 public MethodSignature( Method method )
044 {
045 this.name = method.getName();
046 this.parameterTypes = Arrays.asList( method.getParameterTypes() );
047 }
048
049 //----------------------------------------------------------------------------------------------------------------------
050 // Canonical Methods
051 //----------------------------------------------------------------------------------------------------------------------
052
053 public boolean equals( Object o )
054 {
055 if( this == o )
056 {
057 return true;
058 }
059 if( o == null || getClass() != o.getClass() )
060 {
061 return false;
062 }
063 final MethodSignature that = ( MethodSignature ) o;
064 if( !name.equals( that.name ) )
065 {
066 return false;
067 }
068 if( !parameterTypes.equals( that.parameterTypes ) )
069 {
070 return false;
071 }
072 return true;
073 }
074
075 public int hashCode()
076 {
077 int result;
078 result = name.hashCode();
079 result = 29 * result + parameterTypes.hashCode();
080 return result;
081 }
082 }
083