Package com.sap.cloud.sdk.typeconverter
Class ConvertedObject<T>
java.lang.Object
com.sap.cloud.sdk.typeconverter.ConvertedObject<T>
- Type Parameters:
T
- The type of the contained object.
Wrapper class enclosing the result of a conversion. The conversion may or may not have succeeded, therefore some
accessor methods are given to handle those cases graciously.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
boolean
get()
Retrieves the converted object.int
hashCode()
boolean
Checks whether the conversion succeeded and the value could be converted.boolean
Checks whether the conversion failed and the value could not be converted.static <T> ConvertedObject<T>
of
(T convertedObject) Creates aConvertedObject
containing the given object as its value.static <T> ConvertedObject<T>
Creates aConvertedObject
containingnull
as its value.static <T> ConvertedObject<T>
ofNull()
Creates aConvertedObject
containingnull
as its value.Returns the contained value, or the given default value if the object was not convertible.orNull()
Returns the contained value, ornull
if the object was not convertible.toString()
-
Constructor Details
-
ConvertedObject
-
-
Method Details
-
get
Retrieves the converted object.- Returns:
- The converted object. May be
null
. - Throws:
ObjectNotConvertibleException
- If the object is not convertible.
-
orNull
Returns the contained value, ornull
if the object was not convertible.- Returns:
- The converted object, or
null
if the object was not convertible.
-
orElse
Returns the contained value, or the given default value if the object was not convertible.- Parameters:
defaultValue
- The value to return in case thisConvertedObject
was not convertible.- Returns:
- The converted object, or the given default value if the object was not convertible.
-
isConvertible
public boolean isConvertible()Checks whether the conversion succeeded and the value could be converted.- Returns:
true
if the value could be converted,false
else.
-
of
Creates aConvertedObject
containing the given object as its value.- Type Parameters:
T
- The type of the object to wrap.- Parameters:
convertedObject
- The object to wrap in aConvertedObject
.- Returns:
- A
ConvertedObject
wrappingconvertedObject
.
-
ofNull
Creates aConvertedObject
containingnull
as its value. The reason to use this method might be that no object was given to convert.- Type Parameters:
T
- The type the contained value should have.- Returns:
- A
ConvertedObject
containing onlynull
.
-
ofNotConvertible
Creates aConvertedObject
containingnull
as its value. The reason to use this method might be that the given object could not be converted.- Type Parameters:
T
- The type the contained value should have.- Returns:
- A
ConvertedObject
containing onlynull
.
-
getObject
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-
isNotConvertible
public boolean isNotConvertible()Checks whether the conversion failed and the value could not be converted.- Returns:
true
if the value could not be converted,false
else.
-