Top Description Inners Fields Constructors Methods
org.easymock.bytebuddy.implementation

public Class HashCodeMethod

extends Object
implements Implementation
Class Inheritance
All Implemented Interfaces
org.easymock.bytebuddy.implementation.Implementation, org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable
Annotations
@Enhance
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, org.easymock.bytebuddy.build.HashCodeAndEqualsPlugin, org.easymock.bytebuddy.description.field.FieldDescription, org.easymock.bytebuddy.description.method.MethodDescription, org.easymock.bytebuddy.description.type.TypeDefinition, .TypeDescription, org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType, org.easymock.bytebuddy.implementation.bytecode.*, org.easymock.bytebuddy.implementation.bytecode.constant.ClassConstant, .IntegerConstant, org.easymock.bytebuddy.implementation.bytecode.member.FieldAccess, .MethodInvocation, .MethodReturn, .MethodVariableAccess, org.easymock.bytebuddy.matcher.ElementMatcher, org.easymock.bytebuddy.jar.asm.Label, .MethodVisitor, .Opcodes, java.util.ArrayList, .Arrays, .List

An implementation of 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.

Nested and Inner Type Summary

Modifier and TypeClass 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 enum
HashCodeMethod.ValueTransformer

A value transformer that is responsible for resolving a field value to an int value.

Field Summary

Modifier and TypeField and Description
private static final int
DEFAULT_MULTIPLIER

The default multiplier for each value before adding a field's hash code value which should be a prime number.

private static final int
DEFAULT_OFFSET

The default offset which should be a prime number.

private static final MethodDescription.InDefinedShape
private static final MethodDescription.InDefinedShape
private final ElementMatcher.Junction<? super FieldDescription.InDefinedShape>
ignored

A matcher to filter fields that should not be used for a hash codes computation.

private final int
multiplier

A multiplier for each value before adding a field's hash code value.

private final ElementMatcher.Junction<? super FieldDescription.InDefinedShape>
nonNullable

A matcher to determine fields of a reference type that cannot be null.

private final HashCodeMethod.OffsetProvider
offsetProvider

The hash code's offset provider.

Constructor Summary

AccessConstructor and Description
protected
HashCodeMethod(HashCodeMethod.OffsetProvider
The hash code's offset provider.
offsetProvider
)

Creates a new hash code method implementation.

private
HashCodeMethod(HashCodeMethod.OffsetProvider
The hash code's offset provider.
offsetProvider
,
int
A multiplier for each value before adding a field's hash code value
multiplier
,
ElementMatcher.Junction<? super FieldDescription.InDefinedShape>
A matcher to filter fields that should not be used for a hash codes computation.
ignored
,
ElementMatcher.Junction<? super FieldDescription.InDefinedShape>
A matcher to determine fields of a reference type that cannot be null.
nonNullable
)

Creates a new hash code method implementation.

Method Summary

Modifier and TypeMethod and Description
public ByteCodeAppender
appender(Implementation.Target
The target of the current implementation.
implementationTarget
)

Implements org.easymock.bytebuddy.implementation.Implementation.appender.

Creates a byte code appender that determines the implementation of the instrumented type's methods.
public InstrumentedType
prepare(InstrumentedType
The instrumented type in its current form.
instrumentedType
)

Implements org.easymock.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable.prepare.

Prepares a given instrumented type.
public static HashCodeMethod

Returns:

A hash code method implementation that bases the hash code on a fixed value.
usingDefaultOffset
()

Creates a hash code method implementation that bases the hash code on a fixed value.

public static HashCodeMethod

Returns:

A hash code method implementation that bases the hash code on a fixed value.
usingOffset
(int
The fixed value.
value
)

Creates a hash code method implementation that bases the hash code on a fixed value.

public static HashCodeMethod

Returns:

A hash code method implementation that bases the hash code on the instrumented type's super class's hash code value.
usingSuperClassOffset
()

Creates a hash code method implementation that bases the hash code on the instrumented type's super class's hash code value.

public static HashCodeMethod

Returns:

A hash code method implementation that bases the hash code on the instrumented type's class constant's hash code.
usingTypeHashOffset
(boolean
true if the type should be resolved from the instance and not be set as the declaring class.
dynamic
)

Creates a hash code method implementation that bases the hash code on the instrumented type's class constant's hash code..

public HashCodeMethod

Returns:

A new version of this hash code method implementation that also ignores any fields matched by the provided matcher.
withIgnoredFields
(ElementMatcher<? super FieldDescription.InDefinedShape>
A matcher to specify any fields that should be ignored.
ignored
)

Returns a new version of this hash code method implementation that ignores the specified fields additionally to any previously specified fields.

public Implementation

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.
withMultiplier
(int
The multiplier to use for any hash code before adding any field's hash code.
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.

public HashCodeMethod

Returns:

A new version of this hash code method implementation that also does not apply null value checks to any fields matched by the provided matcher.
withNonNullableFields
(ElementMatcher<? super FieldDescription.InDefinedShape>
A matcher to specify any fields that should not be guarded against null values.
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait