@HashCodeAndEqualsPlugin.Enhance public class HashCodeMethod extends Object implements Implementation
Object.hashCode() that takes a class's declared fields into consideration. A hash code is computed by transforming
primitive field types to an int value and by summing those values up starting from a given offset after multiplying any previous value
with a multiplier. Reference values are checked against null values unless specified otherwise.| Modifier and Type | Class and Description |
|---|---|
protected static class |
HashCodeMethod.Appender
A byte code appender to implement a hash code method.
|
protected static interface |
HashCodeMethod.NullValueGuard
A guard against
null values for fields with reference types. |
protected static interface |
HashCodeMethod.OffsetProvider
An offset provider is responsible for supplying the initial hash code.
|
protected static class |
HashCodeMethod.ValueTransformer
A value transformer that is responsible for resolving a field value to an
int value. |
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.TargetInstrumentedType.Prepareable.NoOp| Modifier | Constructor and Description |
|---|---|
protected |
HashCodeMethod(HashCodeMethod.OffsetProvider offsetProvider)
Creates a new hash code method implementation.
|
| Modifier and Type | Method and Description |
|---|---|
ByteCodeAppender |
appender(Implementation.Target implementationTarget)
Creates a byte code appender that determines the implementation of the instrumented type's methods.
|
InstrumentedType |
prepare(InstrumentedType instrumentedType)
Prepares a given instrumented type.
|
static HashCodeMethod |
usingDefaultOffset()
Creates a hash code method implementation that bases the hash code on a fixed value.
|
static HashCodeMethod |
usingOffset(int value)
Creates a hash code method implementation that bases the hash code on a fixed value.
|
static HashCodeMethod |
usingSuperClassOffset()
Creates a hash code method implementation that bases the hash code on the instrumented type's super class's hash code value.
|
static HashCodeMethod |
usingTypeHashOffset(boolean dynamic)
Creates a hash code method implementation that bases the hash code on the instrumented type's class constant's hash code..
|
HashCodeMethod |
withIgnoredFields(ElementMatcher<? super FieldDescription.InDefinedShape> ignored)
Returns a new version of this hash code method implementation that ignores the specified fields additionally to any
previously specified fields.
|
Implementation |
withMultiplier(int multiplier)
Returns a new version of this hash code method implementation that uses the given multiplier onto any given hash code before adding a
field's hash code.
|
HashCodeMethod |
withNonNullableFields(ElementMatcher<? super FieldDescription.InDefinedShape> nonNullable)
Returns a new version of this hash code 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. |
protected HashCodeMethod(HashCodeMethod.OffsetProvider offsetProvider)
offsetProvider - The hash code's offset provider.public static HashCodeMethod usingSuperClassOffset()
public static HashCodeMethod usingTypeHashOffset(boolean dynamic)
dynamic - true if the type should be resolved from the instance and not be set as the declaring class.public static HashCodeMethod usingDefaultOffset()
public static HashCodeMethod usingOffset(int value)
value - The fixed value.public HashCodeMethod withIgnoredFields(ElementMatcher<? super FieldDescription.InDefinedShape> ignored)
ignored - A matcher to specify any fields that should be ignored.public HashCodeMethod withNonNullableFields(ElementMatcher<? super FieldDescription.InDefinedShape> nonNullable)
null value check for the specified fields
if they have a reference type additionally to any previously specified fields.nonNullable - A matcher to specify any fields that should not be guarded against null values.null value checks to any fields matched by
the provided matcher.public Implementation withMultiplier(int multiplier)
multiplier - The multiplier to use for any hash code before adding any field's hash code.public InstrumentedType prepare(InstrumentedType instrumentedType)
prepare in interface InstrumentedType.PrepareableinstrumentedType - The instrumented type in its current form.public ByteCodeAppender appender(Implementation.Target implementationTarget)
appender in interface ImplementationimplementationTarget - The target of the current implementation.InstrumentedType.Prepareable.prepare(InstrumentedType).Copyright © 2014–2023. All rights reserved.