Object#hashCode()
and Object#equals(Object)
methods to a class if the
Enhance
annotation is present and no explicit method declaration was added. This plugin does not need to be closed.
Modifier and Type | Class and Description |
---|---|
protected static enum | HashCodeAndEqualsPlugin.AnnotationOrderComparator
A comparator that arranges fields in the order of |
public static @interface | HashCodeAndEqualsPlugin.Enhance
Instructs the |
public static @interface | HashCodeAndEqualsPlugin.Sorted
Determines the sort order of fields for the equality check when implementing the |
public static @interface | HashCodeAndEqualsPlugin.ValueHandling
Determines how a field should be used within generated hash code and equality methods. |
protected static class | HashCodeAndEqualsPlugin.ValueMatcher
An element matcher for a |
public static class | HashCodeAndEqualsPlugin.WithNonNullableFields
A version of the |
Access | Constructor and Description |
---|---|
public | |
public | HashCodeAndEqualsPlugin(String
Defines the binary name of a runtime-visible annotation type that should be added to the
parameter of the annotationType)Object#equals(Object) method, or null if no such name
should be defined.Creates a new hash code equals plugin. |
Modifier and Type | Method and Description |
---|---|
public DynamicType. | apply(DynamicType.
The builder to use as a basis for the applied transformation. builder,The type being transformed. typeDescription, ClassFileLocator A class file locator that can locate other types in the scope of the project. classFileLocator)Implements net. |
public void | apply(MethodVisitor
The method visitor to which the attributes that are represented by this attribute
appender are written to. methodVisitor, MethodDescription The description of the method for which the given method visitor creates an
instrumentation for. methodDescription, AnnotationValueFilter The annotation value filter to apply when the annotations are written. annotationValueFilter)Implements net. |
public void | close()
Implements java. |
public Plugin | make()
Implements net. |
public MethodAttributeAppender | make(TypeDescription
The type for which a method attribute appender is to be applied for. typeDescription)Implements net. |
public boolean | matches(TypeDescription
The instance to be matched or target)null .Implements net. |
protected ElementMatcher | Returns: The actual matcher to identify non-nullable fields.The matcher that identifies fields that are either nullable or non-nullable. matcher)Resolves the matcher to identify non-nullable fields. |
annotationType | back to summary |
---|---|
private final String annotationType Defines the binary name of a runtime-visible annotation type that should be added to the parameter of the
|
ENHANCE_INCLUDE_SYNTHETIC_FIELDS | back to summary |
---|---|
private static final MethodDescription. A description of the |
ENHANCE_INVOKE_SUPER | back to summary |
---|---|
private static final MethodDescription. A description of the |
ENHANCE_PERMIT_SUBCLASS_EQUALITY | back to summary |
---|---|
private static final MethodDescription. A description of the |
ENHANCE_SIMPLE_COMPARISON_FIRST | back to summary |
---|---|
private static final MethodDescription. A description of the |
ENHANCE_USE_TYPE_HASH_CONSTANT | back to summary |
---|---|
private static final MethodDescription. A description of the |
SORTED_VALUE | back to summary |
---|---|
private static final MethodDescription. A description of the |
VALUE_HANDLING_VALUE | back to summary |
---|---|
private static final MethodDescription. A description of the |
HashCodeAndEqualsPlugin | back to summary |
---|---|
public HashCodeAndEqualsPlugin() Creates a new hash code equals plugin. |
HashCodeAndEqualsPlugin | back to summary |
---|---|
public HashCodeAndEqualsPlugin(String annotationType) Creates a new hash code equals plugin.
|
apply | back to summary |
---|---|
public DynamicType. Implements net. Doc from net. Applies this plugin.
|
apply | back to summary |
---|---|
public void apply(MethodVisitor methodVisitor, MethodDescription methodDescription, AnnotationValueFilter annotationValueFilter) Implements net. Doc from net. Applies this attribute appender to a given method visitor.
|
close | back to summary |
---|---|
public void close() Implements java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in |
make | back to summary |
---|---|
public Plugin make() Implements net. Doc from net. Returns a plugin that can be used for a transformation and which is subsequently closed.
|
make | back to summary |
---|---|
public MethodAttributeAppender make(TypeDescription typeDescription) Implements net. Doc from net. Returns a method attribute appender that is applicable for a given type description.
|
matches | back to summary |
---|---|
public boolean matches(TypeDescription target) Implements net. Doc from net. Matches a target against this element matcher.
|
nonNullable | back to summary |
---|---|
protected ElementMatcher Resolves the matcher to identify non-nullable fields.
|
Sorted
.
Modifier and Type | Field and Description |
---|---|
public static final HashCodeAndEqualsPlugin. | INSTANCE
The singleton instance. |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public int | compare(FieldDescription.
the first object to be compared. left,the second object to be compared. rightImplements java. |
public static HashCodeAndEqualsPlugin. | |
public static HashCodeAndEqualsPlugin. |
INSTANCE | back to summary |
---|---|
public static final HashCodeAndEqualsPlugin. The singleton instance. |
AnnotationOrderComparator | back to summary |
---|---|
private AnnotationOrderComparator() |
compare | back to summary |
---|---|
public int compare(FieldDescription. Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that
|
valueOf | back to summary |
---|---|
public static HashCodeAndEqualsPlugin. |
values | back to summary |
---|---|
public static HashCodeAndEqualsPlugin. |
HashCodeAndEqualsPlugin
to generate Object#hashCode()
and Object#equals(Object)
for the annotated
class unless these methods are already declared explicitly.
Modifier and Type | Class and Description |
---|---|
public static enum | HashCodeAndEqualsPlugin.Enhance.InvokeSuper
A strategy for determining the base value of a hash code or equality contract. |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if synthetic fields should be included.Determines if synthetic fields should be included in the hash code and equality contract. |
public HashCodeAndEqualsPlugin. | Returns: A strategy for determining the base value.Determines the base value of any added method, i.e. if hash code or equality is based on the super type or not. |
public boolean | Returns: true if instances subclasses of the instrumented type are accepted upon an equality check.Determines if instances subclasses of the instrumented type are accepted upon an equality check. |
public boolean | Returns: true if fields with simple comparison methods should be compared first.Determines if fields with primitive types, then enumeration types, then primtive wrapper types and then |
public boolean | Returns: true if the hash code constant should be derived of the instrumented type.Determines if the hash code constant should be derived of the instrumented type. |
includeSyntheticFields | back to summary |
---|---|
public boolean includeSyntheticFields() Determines if synthetic fields should be included in the hash code and equality contract.
|
invokeSuper | back to summary |
---|---|
public HashCodeAndEqualsPlugin. Determines the base value of any added method, i.e. if hash code or equality is based on the super type or not.
|
permitSubclassEquality | back to summary |
---|---|
public boolean permitSubclassEquality() Determines if instances subclasses of the instrumented type are accepted upon an equality check.
|
simpleComparisonsFirst | back to summary |
---|---|
public boolean simpleComparisonsFirst() Determines if fields with primitive types, then enumeration types, then primtive wrapper types and then
|
useTypeHashConstant | back to summary |
---|---|
public boolean useTypeHashConstant() Determines if the hash code constant should be derived of the instrumented type. If
|
Modifier and Type | Field and Description |
---|---|
public static final HashCodeAndEqualsPlugin. | ALWAYS
Always invokes the super class's hash code and equality methods. |
public static final HashCodeAndEqualsPlugin. | IF_ANNOTATED
Only invokes the super method's hash code and equality methods if the super class is also annotated with |
public static final HashCodeAndEqualsPlugin. | IF_DECLARED
Only invokes the super method's hash code and equality methods if any super class that is not |
public static final HashCodeAndEqualsPlugin. | NEVER
Never invokes the super class's hash code and equality methods. |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
protected abstract EqualsMethod | Returns: The equals method to use.The instrumented type. instrumentedType)Resolves the equals method to use. |
protected abstract HashCodeMethod | Returns: The hash code method to use.The instrumented type. instrumentedType, boolean true if the base hash should be based on the instrumented class's type.true if subclasses can be equal to their base classes.Resolves the hash code method to use. |
public static HashCodeAndEqualsPlugin. | |
public static HashCodeAndEqualsPlugin. |
ALWAYS | back to summary |
---|---|
public static final HashCodeAndEqualsPlugin. Always invokes the super class's hash code and equality methods. |
IF_ANNOTATED | back to summary |
---|---|
public static final HashCodeAndEqualsPlugin. Only invokes the super method's hash code and equality methods if the super class is also annotated with |
IF_DECLARED | back to summary |
---|---|
public static final HashCodeAndEqualsPlugin. Only invokes the super method's hash code and equality methods if any super class that is not |
NEVER | back to summary |
---|---|
public static final HashCodeAndEqualsPlugin. Never invokes the super class's hash code and equality methods. |
InvokeSuper | back to summary |
---|---|
private InvokeSuper() |
equalsMethod | back to summary |
---|---|
protected abstract EqualsMethod equalsMethod(TypeDescription instrumentedType) Resolves the equals method to use.
|
hashCodeMethod | back to summary |
---|---|
protected abstract HashCodeMethod hashCodeMethod(TypeDescription instrumentedType, boolean typeHash, boolean subclassEquality) Resolves the hash code method to use.
|
valueOf | back to summary |
---|---|
public static HashCodeAndEqualsPlugin. |
values | back to summary |
---|---|
public static HashCodeAndEqualsPlugin. |
Object#equals(Object)
method. Any field
that is not annotated is considered with a value of Sorted#DEFAULT
where fields with a higher value are checked for equality
first. This sort order is applied first after which the type order is considered if Enhance#simpleComparisonsFirst()
is considered
as additional sort criteria.
Modifier and Type | Field and Description |
---|---|
public static final int | DEFAULT
The default sort weight. |
Modifier and Type | Method and Description |
---|---|
public int | Returns: The value for the sort order where fields with higher values are checked for equality first.The value for the sort order where fields with higher values are checked for equality first. |
DEFAULT | back to summary |
---|---|
public static final int DEFAULT The default sort weight. |
value | back to summary |
---|---|
public int value() The value for the sort order where fields with higher values are checked for equality first.
|
Modifier and Type | Class and Description |
---|---|
public static enum | HashCodeAndEqualsPlugin.ValueHandling.Sort
Determines how a field should be handled. |
Modifier and Type | Method and Description |
---|---|
public HashCodeAndEqualsPlugin. |
value | back to summary |
---|---|
public HashCodeAndEqualsPlugin. Determines the handling of the annotated field.
|
Modifier and Type | Field and Description |
---|---|
public static final HashCodeAndEqualsPlugin. | IGNORE
Excludes the field from hash code and equality methods. |
public static final HashCodeAndEqualsPlugin. | REVERSE_NULLABILITY
Reverses the nullability of the field, i.e. assumes this field to be non-null or |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public static HashCodeAndEqualsPlugin. | |
public static HashCodeAndEqualsPlugin. |
IGNORE | back to summary |
---|---|
public static final HashCodeAndEqualsPlugin. Excludes the field from hash code and equality methods. |
REVERSE_NULLABILITY | back to summary |
---|---|
public static final HashCodeAndEqualsPlugin. Reverses the nullability of the field, i.e. assumes this field to be non-null or |
Sort | back to summary |
---|---|
private Sort() |
valueOf | back to summary |
---|---|
public static HashCodeAndEqualsPlugin. |
values | back to summary |
---|---|
public static HashCodeAndEqualsPlugin. |
ValueHandling
annotation.
Modifier and Type | Field and Description |
---|---|
private final HashCodeAndEqualsPlugin. | sort
The matched value. |
Access | Constructor and Description |
---|---|
protected | ValueMatcher(HashCodeAndEqualsPlugin.
The matched value. sortCreates a new value matcher. |
Modifier and Type | Method and Description |
---|---|
protected boolean | doMatch(FieldDescription
The instance to be matched. target)Implements abstract net. null .
|
sort | back to summary |
---|---|
private final HashCodeAndEqualsPlugin. The matched value. |
ValueMatcher | back to summary |
---|---|
protected ValueMatcher(HashCodeAndEqualsPlugin. Creates a new value matcher.
|
doMatch | back to summary |
---|---|
protected boolean doMatch(FieldDescription target) Implements abstract net. Doc from net. Matches the supplied value if it was found not to be
|
HashCodeAndEqualsPlugin
that assumes that all fields are non-nullable unless they are explicitly marked.
Access | Constructor and Description |
---|---|
public | WithNonNullableFields()
Creates a new hash code equals plugin where fields are assumed nullable by default. |
public | WithNonNullableFields(String
Defines the binary name of a runtime-visible annotation type that should be added to the
parameter of the annotationType)Object#equals(Object) method, or null if no such name
should be defined.Creates a new hash code equals plugin where fields are assumed nullable by default. |
Modifier and Type | Method and Description |
---|---|
protected ElementMatcher | nonNullable(ElementMatcher<FieldDescription>
The matcher that identifies fields that are either nullable or non-nullable. matcher)Overrides net. |
WithNonNullableFields | back to summary |
---|---|
public WithNonNullableFields() Creates a new hash code equals plugin where fields are assumed nullable by default. |
WithNonNullableFields | back to summary |
---|---|
public WithNonNullableFields(String annotationType) Creates a new hash code equals plugin where fields are assumed nullable by default.
|
nonNullable | back to summary |
---|---|
protected ElementMatcher Overrides net. Doc from net. Resolves the matcher to identify non-nullable fields.
|