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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanget()Retrieves the converted object.inthashCode()booleanChecks whether the conversion succeeded and the value could be converted.booleanChecks whether the conversion failed and the value could not be converted.static <T> ConvertedObject<T>of(T convertedObject) Creates aConvertedObjectcontaining the given object as its value.static <T> ConvertedObject<T>Creates aConvertedObjectcontainingnullas its value.static <T> ConvertedObject<T>ofNull()Creates aConvertedObjectcontainingnullas its value.Returns the contained value, or the given default value if the object was not convertible.orNull()Returns the contained value, ornullif 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, ornullif the object was not convertible.- Returns:
- The converted object, or
nullif 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 thisConvertedObjectwas 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:
trueif the value could be converted,falseelse.
-
of
Creates aConvertedObjectcontaining 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
ConvertedObjectwrappingconvertedObject.
-
ofNull
Creates aConvertedObjectcontainingnullas 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
ConvertedObjectcontaining onlynull.
-
ofNotConvertible
Creates aConvertedObjectcontainingnullas 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
ConvertedObjectcontaining 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:
trueif the value could not be converted,falseelse.
-