public class Substitution
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.Map<TypeVariable,ReferenceType> |
map
The map from type variables to concrete types.
|
private java.util.Map<java.lang.reflect.Type,ReferenceType> |
rawMap
Map on reflection types - used for testing bounds.
|
private static java.util.function.BiFunction<ReferenceType,ReferenceType,ReferenceType> |
requireSameEntry
Throws an exception if its arguments are different non-null values.
|
Constructor and Description |
---|
Substitution()
Create an empty substitution.
|
Substitution(java.util.List<TypeVariable> parameters,
java.util.List<ReferenceType> arguments)
Create a substitution from the type parameters to the corresponding type arguments.
|
Substitution(java.util.List<TypeVariable> parameters,
ReferenceType... arguments)
Create a substitution from the type parameters to the corresponding type arguments.
|
Substitution(Substitution substitution)
Make a copy of the given substitution.
|
Substitution(TypeVariable parameter,
ReferenceType argument)
Create a substitution that maps the given type parameter to the given type argument.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(@Nullable java.lang.Object obj) |
Substitution |
extend(java.util.List<TypeVariable> parameters,
java.util.List<ReferenceType> arguments)
Creates a new substitution that contains the mappings of this substitution, extended by the
given mappings.
|
Substitution |
extend(Substitution other)
Creates a new substitution that contains the entries of two substitutions.
|
@Nullable ReferenceType |
get(java.lang.reflect.Type parameter)
Returns the value for the given
Type |
@Nullable ReferenceType |
get(TypeVariable parameter)
Returns the concrete type mapped from the type variable by this substitution.
|
ReferenceType |
getOrDefault(TypeVariable parameter,
ReferenceType defaultValue)
Returns the concrete type mapped from the type variable by this substitution.
|
int |
hashCode() |
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.
|
boolean |
isEmpty()
Indicates whether this substitution is empty.
|
java.util.Set<TypeVariable> |
keySet()
Returns the type variables mapped from by this.
|
void |
print()
Print the entries of this substitution to standard out on multiple lines.
|
private void |
put(TypeVariable typeParameter,
ReferenceType type)
Add a type variable to concrete type mapping to the substitution.
|
java.lang.String |
toString() |
private java.util.Map<TypeVariable,ReferenceType> map
private java.util.Map<java.lang.reflect.Type,ReferenceType> rawMap
map
: those that are type parameters as opposed to other type variables such as wildcards.private static java.util.function.BiFunction<ReferenceType,ReferenceType,ReferenceType> requireSameEntry
public Substitution()
public Substitution(Substitution substitution)
substitution
- the substitution to copypublic Substitution(TypeVariable parameter, ReferenceType argument)
parameter
- the type parameterargument
- the type argumentpublic Substitution(java.util.List<TypeVariable> parameters, ReferenceType... arguments)
parameters
- the type parametersarguments
- the type argumentspublic Substitution(java.util.List<TypeVariable> parameters, java.util.List<ReferenceType> arguments)
parameters
- the type parametersarguments
- the type argumentspublic boolean equals(@Nullable java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isConsistentWith(Substitution substitution)
extend(Substitution)
.substitution
- the other substitution to check for consistency with this substitutionpublic Substitution extend(java.util.List<TypeVariable> parameters, java.util.List<ReferenceType> arguments)
parameters
- the type parametersarguments
- the type argumentspublic Substitution extend(Substitution other)
other
- the substitution to add to this substitutionpublic @Nullable ReferenceType get(TypeVariable parameter)
parameter
- the variablepublic ReferenceType getOrDefault(TypeVariable parameter, ReferenceType defaultValue)
parameter
- the variabledefaultValue
- the default value to return if the variable is not in the substitutiondefault
if
there is no type for the variablepublic @Nullable ReferenceType get(java.lang.reflect.Type parameter)
Type
parameter
- the type variablepublic java.util.Set<TypeVariable> keySet()
public void print()
private void put(@UnknownInitialization Substitution this, TypeVariable typeParameter, ReferenceType type)
typeParameter
- the type variabletype
- the concrete typepublic boolean isEmpty()