Class EqualsMethod

  • All Implemented Interfaces:
    InstrumentedType.Prepareable, Implementation

    public class EqualsMethod
    extends java.lang.Object
    implements Implementation
    An implementation of Object.equals(Object) that takes a class's declared fields into consideration. Equality is resolved by comparing two instances of the same or a compatible class field by field where reference fields must either both be null or where the field value of the instance upon which the method is invoked returns true upon calling the value's equals method. For arrays, the corresponding utilities of Arrays are used.
    • Constructor Detail

      • EqualsMethod

        protected EqualsMethod​(EqualsMethod.SuperClassCheck superClassCheck)
        Creates a new equals method implementation.
        Parameters:
        superClassCheck - The baseline equality to check.
    • Method Detail

      • requiringSuperClassEquality

        public static EqualsMethod requiringSuperClassEquality()
        Creates an equals implementation that invokes the super class's Object.equals(Object) method first.
        Returns:
        An equals implementation that invokes the super class's Object.equals(Object) method first.
      • isolated

        public static EqualsMethod isolated()
        Creates an equals method implementation that does not invoke the super class's Object.equals(Object) method.
        Returns:
        An equals method implementation that does not invoke the super class's Object.equals(Object) method.
      • withIgnoredFields

        public EqualsMethod withIgnoredFields​(ElementMatcher<? super FieldDescription.InDefinedShape> ignored)
        Returns a new version of this equals method implementation that ignores the specified fields additionally to any previously specified fields.
        Parameters:
        ignored - A matcher to specify any fields that should be ignored.
        Returns:
        A new version of this equals method implementation that also ignores any fields matched by the provided matcher.
      • withNonNullableFields

        public EqualsMethod withNonNullableFields​(ElementMatcher<? super FieldDescription.InDefinedShape> nonNullable)
        Returns a new version of this equals method implementation that does not apply a null value check for the specified fields if they have a reference type additionally to any previously specified fields.
        Parameters:
        nonNullable - A matcher to specify any fields that should not be guarded against null values.
        Returns:
        A new version of this equals method implementation that also does not apply null value checks to any fields matched by the provided matcher.
      • withSubclassEquality

        public Implementation withSubclassEquality()
        Returns a new version of this equals method implementation that permits subclasses of the instrumented type to be equal to instances of the instrumented type instead of requiring an exact match.
        Returns:
        A new version of this equals method implementation that permits subclasses of the instrumented type to be equal to instances of the instrumented type instead of requiring an exact match.
      • appender

        public ByteCodeAppender appender​(Implementation.Target implementationTarget)
        Description copied from interface: Implementation
        Creates a byte code appender that determines the implementation of the instrumented type's methods.
        Specified by:
        appender in interface Implementation
        Parameters:
        implementationTarget - The target of the current implementation.
        Returns:
        A byte code appender for implementing methods delegated to this implementation. This byte code appender is also responsible for handling methods that were added by this implementation on the call to InstrumentedType.Prepareable.prepare(InstrumentedType).