public class Subjectivity
extends java.lang.Object
This class allows to substitute objects with views which expose different
Object.equals(Object)
and Object.hashCode()
implementations.
It does not work on primitive types, but their boxed counterparts. If you
provide a Subjective
for a boxed primitive class it is also
a good idea to provide one for its one-dimensional array type. E.g. if
you provide a subjective for Double
you should also provide one
for double[]
.
Hashing of arrays is usually done flat, but you can change this by
setting the deep
flag in the constructors to true
.
This will influence all arrays, not just the ones which are handled
by subjectives.
Constructor and Description |
---|
Subjectivity(boolean deep,
java.lang.Iterable<Subjective<?>> subjects)
Constructor.
|
Subjectivity(boolean deep,
Subjective<?>... subjects)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
substitute(java.lang.Object obj)
Substitute the given object.
|
java.lang.Object |
substitute0(java.lang.Object obj)
Substitute the given object which may be
null . |
public Subjectivity(boolean deep, @NotNull java.lang.Iterable<Subjective<?>> subjects)
deep
- make equals and hashcode work deep?subjects
- subjective views used by this subjectivitypublic Subjectivity(boolean deep, @NotNull Subjective<?>... subjects)
deep
- make equals and hashcode work deep?subjects
- subjective views used by this subjectivity@NotNull public java.lang.Object substitute(@NotNull java.lang.Object obj)
It is strictly recommended to use a substitute only for checking equality or hashing.
obj
- object to be substituted, not null
obj
if there is no substitution for the given objectsubstitute0(Object)
@Nullable public java.lang.Object substitute0(@Nullable java.lang.Object obj)
null
.obj
- object to be substituted, possibly null
obj
if there is no substitution for the given object, or it is null