Package randoop.types

Class Substitution


  • public class Substitution
    extends Object
    A substitution maps type parameters/variables (including wildcards) to concrete types. It represents the instantiation of a generic class to a parameterized type.
    • Constructor Detail

      • Substitution

        public Substitution()
        Create an empty substitution.
      • Substitution

        public Substitution​(Substitution substitution)
        Make a copy of the given substitution.
        Parameters:
        substitution - the substitution to copy
      • Substitution

        public Substitution​(TypeVariable parameter,
                            ReferenceType argument)
        Create a substitution that maps the given type parameter to the given type argument.
        Parameters:
        parameter - the type parameter
        argument - the type argument
      • Substitution

        public Substitution​(List<TypeVariable> parameters,
                            ReferenceType... arguments)
        Create a substitution from the type parameters to the corresponding type arguments.
        Parameters:
        parameters - the type parameters
        arguments - the type arguments
      • Substitution

        public Substitution​(List<TypeVariable> parameters,
                            List<ReferenceType> arguments)
        Create a substitution from the type parameters to the corresponding type arguments.
        Parameters:
        parameters - the type parameters
        arguments - the type arguments
    • Method Detail

      • equals

        public boolean equals​(Object obj)
        Overrides:
        equals in class Object
        Returns:
        true if the substitution maps are identical and false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isConsistentWith

        public boolean isConsistentWith​(Substitution substitution)
        Two substitutions are consistent if their type variables are disjoint or, if they both map the same type variable, they map it to the same type. This is the test for whether this substitution can be extended by the other substitution using extend(Substitution).
        Parameters:
        substitution - the other substitution to check for consistency with this substitution
        Returns:
        true if the substitutions are consistent, false otherwise
      • extend

        public Substitution extend​(List<TypeVariable> parameters,
                                   List<ReferenceType> arguments)
        Creates a new substitution that contains the mappings of this substitution, extended by the given mappings. If this and the additional mappings contain the same type variable, both must map it to the same type.
        Parameters:
        parameters - the type parameters
        arguments - the type arguments
        Returns:
        a new substitution that is this substitution extended by the given mappings
      • extend

        public Substitution extend​(Substitution other)
        Creates a new substitution that contains the entries of two substitutions. If both substitutions contain the same type variable, they must map to the same type.
        Parameters:
        other - the substitution to add to this substitution
        Returns:
        a new substitution that is this substitution extended by the given substitution
      • get

        public ReferenceType get​(TypeVariable parameter)
        Returns the concrete type mapped from the type variable by this substitution. Returns null if the variable is not in the substitution.
        Parameters:
        parameter - the variable
        Returns:
        the concrete type mapped from the variable in this substitution, or null if there is no type for the variable
      • getOrDefault

        public ReferenceType getOrDefault​(TypeVariable parameter,
                                          ReferenceType defaultValue)
        Returns the concrete type mapped from the type variable by this substitution. Returns the given default value if the variable is not in the substitution.
        Parameters:
        parameter - the variable
        defaultValue - the default value to return if the variable is not in the substitution
        Returns:
        the concrete type mapped from the variable in this substitution, or default if there is no type for the variable
      • get

        public ReferenceType get​(Type parameter)
        Returns the value for the given Type
        Parameters:
        parameter - the type variable
        Returns:
        the value for the type variable, or null if there is none
      • keySet

        public Set<TypeVariable> keySet()
        Returns the type variables mapped from by this.
        Returns:
        the type variables mapped from by this
      • print

        public void print()
        Print the entries of this substitution to standard out on multiple lines.
      • put

        private void put​(TypeVariable typeParameter,
                         ReferenceType type)
        Add a type variable to concrete type mapping to the substitution.
        Parameters:
        typeParameter - the type variable
        type - the concrete type
      • isEmpty

        public boolean isEmpty()
        Indicates whether this substitution is empty.
        Returns:
        true if this has no substitution pairs, false otherwise