public final class ValueWrapper extends Object implements Serializable
This class only stores the value if it implements Serializable
.
In any case, it stores its runtime type, identity hash code, and string representation determined via String.valueOf(Object)
. If the invocation of String.valueOf(Object)
throws an Exception
, the string representation will take the form of
"<Exception in toString(): " + e + ">"
, where "e" is the caught
exception.
The toString()
method returns the string representation of the
value along with its type and identity hash code.
System.identityHashCode(java.lang.Object)
,
Serialized FormModifier and Type | Method and Description |
---|---|
static ValueWrapper |
create(Object value)
Factory for creating a new
ValueWrapper for the supplied value . |
static ValueWrapper |
create(Object value,
String stringRepresentation)
Factory for creating a new
ValueWrapper for the supplied value
using the supplied custom stringRepresentation . |
Object |
getEphemeralValue()
Returns the original value supplied to
create() . |
int |
getIdentityHashCode()
Returns the value's identity hash code.
|
String |
getStringRepresentation()
Returns the value's string representation.
|
Class<?> |
getType()
Returns the value's runtime type or
null if the value is
null . |
Serializable |
getValue()
|
String |
toString()
Returns the value's string representation along with its type and
identity hash code.
|
public static ValueWrapper create(Object value)
ValueWrapper
for the supplied value
.
If the supplied value
is null
, this method will return a
cached ValueWrapper
suitable for all null
values.
If the supplied value
is already an instance of ValueWrapper
,
it will be returned as is.
value
- the value to wrap; may be null
null
public static ValueWrapper create(Object value, String stringRepresentation)
ValueWrapper
for the supplied value
using the supplied custom stringRepresentation
.
You should use this method when you don't want to rely on the result of the
value's toString()
method.
If the supplied value
is null
, this method will return a
cached ValueWrapper
suitable for all null
values.
If the supplied value
is already an instance of ValueWrapper
,
it will be returned as is if the stringRepresentation
match, otherwise
the original value will be unwrapped and a new ValueWrapper
with the
new stringRepresentation
will be created.
value
- the value to wrap; may be null
stringRepresentation
- a custom rendering of the value; will fallback to
the default behavior if null
null
public Serializable getValue()
getEphemeralValue()
public Class<?> getType()
null
if the value is
null
.public String getStringRepresentation()
The string representation is generated by invoking
String.valueOf(value)
for the value
supplied to create(Object)
.
getValue()
public int getIdentityHashCode()
The identity hash code is generated by invoking
System.identityHashCode(value)
for the value supplied to create(Object)
.
getValue()
public Object getEphemeralValue()
create()
.
If this ValueWrapper
was created by deserialization this method
returns null
.
getValue()
Copyright © 2020. All rights reserved.