Class ValueWrapper
- All Implemented Interfaces:
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.
- Since:
- 1.0
- Author:
- Marc Philipp, Sam Brannen
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ValueWrapper
Factory for creating a newValueWrapper
for the suppliedvalue
.static ValueWrapper
Factory for creating a newValueWrapper
for the suppliedvalue
using the supplied customstringRepresentation
.Returns the original value supplied tocreate()
.int
Returns the value's identity hash code.Returns the value's string representation.Class<?>
getType()
Returns the value's runtime type ornull
if the value isnull
.getValue()
toString()
Returns the value's string representation along with its type and identity hash code.
-
Method Details
-
create
Factory for creating a newValueWrapper
for the suppliedvalue
.If the supplied
value
isnull
, this method will return a cachedValueWrapper
suitable for allnull
values. If the suppliedvalue
is already an instance ofValueWrapper
, it will be returned as is.- Parameters:
value
- the value to wrap; may benull
- Returns:
- a wrapper for the supplied value; never
null
-
create
Factory for creating a newValueWrapper
for the suppliedvalue
using the supplied customstringRepresentation
.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
isnull
, this method will return a cachedValueWrapper
suitable for allnull
values. If the suppliedvalue
is already an instance ofValueWrapper
, it will be returned as is if thestringRepresentation
match, otherwise the original value will be unwrapped and a newValueWrapper
with the newstringRepresentation
will be created.- Parameters:
value
- the value to wrap; may benull
stringRepresentation
- a custom rendering of the value; will fallback to the default behavior ifnull
- Returns:
- a wrapper for the supplied value; never
null
- Since:
- 1.2
-
getValue
- See Also:
-
getType
Returns the value's runtime type ornull
if the value isnull
. -
getStringRepresentation
Returns the value's string representation.The string representation is generated by invoking
String.valueOf(value)
for the value supplied tocreate(Object)
.- See Also:
-
getIdentityHashCode
public int getIdentityHashCode()Returns the value's identity hash code.The identity hash code is generated by invoking
System.identityHashCode(value)
for the value supplied tocreate(Object)
.- See Also:
-
getEphemeralValue
Returns the original value supplied tocreate()
.If this
ValueWrapper
was created by deserialization this method returnsnull
.- Since:
- 1.2
- See Also:
-
toString
Returns the value's string representation along with its type and identity hash code.
-