public final class MetaConfig
extends java.lang.Object
Meta
instances.
Use the default configuration to create new configurations.
Instances must be immutable and thread-safe.Meta.configure(MetaConfig)
,
defaultConfig()
Modifier and Type | Class and Description |
---|---|
static interface |
MetaConfig.InstanceCheckPolicy
Used at the start of
Meta.equals(Object, Object) to check type equivalence. |
static interface |
MetaConfig.ObjectEqualsPolicy
Allows configuration of how objects are considered equal.
|
static interface |
MetaConfig.ObjectHashCodePolicy
Allows configuration of how an object's hash code is generated.
|
static interface |
MetaConfig.ObjectToStringPolicy
Allows configuration of how objects are converted to strings.
|
Modifier and Type | Method and Description |
---|---|
static MetaConfig |
defaultConfig()
The default configuration for
Meta instances. |
MetaConfig.InstanceCheckPolicy |
getInstanceCheckPolicy()
Called at the start of
Meta.equals(Object, Object) to ensure that the 2nd argument is the same type
as the first before it is cast to that type. |
MetaConfig.ObjectEqualsPolicy |
getObjectEqualsPolicy()
Used in
Meta.equals(Object, Object) for any return value from Getter to check whether
values are equal. |
MetaConfig.ObjectHashCodePolicy |
getObjectHashCodePolicy()
Used in
Meta.hashCode(Object) for any return value from Getter . |
MetaConfig.ObjectToStringPolicy |
getObjectToStringPolicy()
Used in
Meta.toString(Object) for any return value from Getter . |
MetaConfig |
withInstanceCheck(MetaConfig.InstanceCheckPolicy policy)
Allows consumers to set special handling for how
Meta.equals(Object, Object) determines whether
the 2nd argument is the same type as the first. |
MetaConfig |
withInstanceofEqualsTypeCheck()
Alters the config to use
thisType.isInstance(thatInstance) instead of
the default thisType == thatInstance.getClass() . |
MetaConfig |
withObjectEqualsChecks(MetaConfig.ObjectEqualsPolicy equalsPolicy,
MetaConfig.ObjectHashCodePolicy hashCodePolicy)
Allows consumers to set special handling for
Getter.get(Object) responses for
Meta.equals(Object, Object) , Meta.hashCode(Object) . |
MetaConfig |
withObjectToString(MetaConfig.ObjectToStringPolicy stringPolicy)
Allows consumers to set special handling for
Getter.get(Object) responses for
Meta.toString(Object) . |
MetaConfig |
withShallowArraySupport()
Alters the configuration to have basic array support.
|
public static MetaConfig defaultConfig()
Meta
instances.
It is not possible to alter the default configuration.
Callers must generate new configurations using methods like
withShallowArraySupport()
and then use Meta.configure(MetaConfig)
to create a new instance with the given configuration.public MetaConfig.InstanceCheckPolicy getInstanceCheckPolicy()
Meta.equals(Object, Object)
to ensure that the 2nd argument is the same type
as the first before it is cast to that type.
The default policy returns true if this.getClass() == that.getClass()
.MetaConfig.InstanceCheckPolicy
,
withInstanceofEqualsTypeCheck()
public MetaConfig.ObjectEqualsPolicy getObjectEqualsPolicy()
Meta.equals(Object, Object)
for any return value from Getter
to check whether
values are equal.
The default policy uses Objects.equals(Object, Object)
.withShallowArraySupport()
public MetaConfig.ObjectHashCodePolicy getObjectHashCodePolicy()
Meta.hashCode(Object)
for any return value from Getter
.
The default policy uses Objects.hashCode(Object)
.withShallowArraySupport()
public MetaConfig.ObjectToStringPolicy getObjectToStringPolicy()
Meta.toString(Object)
for any return value from Getter
.
The default policy uses Objects.toString(Object)
.withShallowArraySupport()
public MetaConfig withInstanceofEqualsTypeCheck()
thisType.isInstance(thatInstance)
instead of
the default thisType == thatInstance.getClass()
.
Use this method if you need subtypes to be equal to the parent type T
.MetaConfig.InstanceCheckPolicy
public MetaConfig withShallowArraySupport()
Getter
returns an array the configuration will support shallow equality, hash code and to string
inspection to determine equivalence.
Refer to the following methods for base implementation details:
Arrays.equals(boolean[], boolean[])
;
Arrays.hashCode(boolean[])
;
Arrays.toString(boolean[])
.Meta.equals(Object, Object)
,
Meta.hashCode(Object)
,
Meta.toString(Object)
public MetaConfig withInstanceCheck(MetaConfig.InstanceCheckPolicy policy)
Meta.equals(Object, Object)
determines whether
the 2nd argument is the same type as the first.policy
- a non-null policywithInstanceofEqualsTypeCheck()
public MetaConfig withObjectEqualsChecks(MetaConfig.ObjectEqualsPolicy equalsPolicy, MetaConfig.ObjectHashCodePolicy hashCodePolicy)
Getter.get(Object)
responses for
Meta.equals(Object, Object)
, Meta.hashCode(Object)
.equalsPolicy
- a non-null equals policyhashCodePolicy
- a non-null hash policywithShallowArraySupport()
public MetaConfig withObjectToString(MetaConfig.ObjectToStringPolicy stringPolicy)
Getter.get(Object)
responses for
Meta.toString(Object)
.stringPolicy
- a non-null to string policywithShallowArraySupport()