Class MethodIdentifier

  • All Implemented Interfaces:
    Serializable

    public final class MethodIdentifier
    extends Object
    implements Serializable
    A unique identification of a method within some class or interface which is class loader-agnostic. Suitable for serialization as well as usage as a hash table key.
    Author:
    David M. Lloyd
    See Also:
    Serialized Form
    • Field Detail

      • CLONE

        public static final MethodIdentifier CLONE
        The method identifier for Object.clone().
      • EQUALS

        public static final MethodIdentifier EQUALS
        The method identifier for Object.equals().
      • FINALIZE

        public static final MethodIdentifier FINALIZE
        The method identifier for Object.finalize().
      • HASH_CODE

        public static final MethodIdentifier HASH_CODE
        The method identifier for Object.hashCode().
      • TO_STRING

        public static final MethodIdentifier TO_STRING
        The method identifier for Object.toString().
    • Method Detail

      • getName

        public String getName()
        Get the method name.
        Returns:
        the method name
      • getParameterTypes

        public String[] getParameterTypes()
        Get the parameter type names, as strings.
        Returns:
        the parameter type names
      • getReturnType

        public String getReturnType()
        Get the method return type name, as a string.
        Returns:
        the method return type name
      • equals

        public boolean equals​(Object other)
        Determine whether this object is equal to another.
        Overrides:
        equals in class Object
        Parameters:
        other - the other object
        Returns:
        true if they are equal, false otherwise
      • equals

        public boolean equals​(MethodIdentifier other)
        Determine whether this object is equal to another.
        Parameters:
        other - the other object
        Returns:
        true if they are equal, false otherwise
      • hashCode

        public int hashCode()
        Get the hash code for this method identifier. The hash code is equal to:
            n * 7 + (r * 7 + a)
         
        where n is the method name's hash code, r is the method return type's name's hash code and a is the result of calling Arrays.hashCode(Object[]) on the parameter type name list (of strings).
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • toString

        public String toString()
        Get the human-readable representation of this identifier.
        Overrides:
        toString in class Object
        Returns:
        the string
      • getIdentifierForMethod

        public static MethodIdentifier getIdentifierForMethod​(Method method)
        Get an identifier for the given reflection method.
        Parameters:
        method - the method
        Returns:
        the identifier
      • getIdentifier

        public static MethodIdentifier getIdentifier​(Class<?> returnType,
                                                     String name,
                                                     Class<?>... parameterTypes)
        Construct a new instance using class objects for the parameter types.
        Parameters:
        returnType - the method return type
        name - the method name
        parameterTypes - the method parameter types
        Returns:
        the identifier
      • getIdentifier

        public static MethodIdentifier getIdentifier​(String returnType,
                                                     String name,
                                                     String... parameterTypes)
        Construct a new instance using string names for the return and parameter types.
        Parameters:
        returnType - the return type name
        name - the method name
        parameterTypes - the method parameter type names
        Returns:
        the identifier