Class ConvertedObject<T>

java.lang.Object
com.sap.cloud.sdk.typeconverter.ConvertedObject<T>
Type Parameters:
T - The type of the contained object.

public class ConvertedObject<T> extends 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
    Modifier
    Constructor
    Description
    protected
    ConvertedObject(boolean notConvertible, T object)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
     
    boolean
     
    get()
    Retrieves the converted object.
     
    int
     
    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 a ConvertedObject containing the given object as its value.
    static <T> ConvertedObject<T>
    Creates a ConvertedObject containing null as its value.
    static <T> ConvertedObject<T>
    Creates a ConvertedObject containing null as its value.
    orElse(T defaultValue)
    Returns the contained value, or the given default value if the object was not convertible.
    Returns the contained value, or null if the object was not convertible.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ConvertedObject

      protected ConvertedObject(boolean notConvertible, @Nullable T object)
  • Method Details

    • get

      @Nullable public T get() throws ObjectNotConvertibleException
      Retrieves the converted object.
      Returns:
      The converted object. May be null.
      Throws:
      ObjectNotConvertibleException - If the object is not convertible.
    • orNull

      @Nullable public T orNull()
      Returns the contained value, or null if the object was not convertible.
      Returns:
      The converted object, or null if the object was not convertible.
    • orElse

      @Nullable public T orElse(@Nullable T defaultValue)
      Returns the contained value, or the given default value if the object was not convertible.
      Parameters:
      defaultValue - The value to return in case this ConvertedObject 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

      @Nonnull public static <T> ConvertedObject<T> of(@Nullable T convertedObject)
      Creates a ConvertedObject containing the given object as its value.
      Type Parameters:
      T - The type of the object to wrap.
      Parameters:
      convertedObject - The object to wrap in a ConvertedObject.
      Returns:
      A ConvertedObject wrapping convertedObject.
    • ofNull

      @Nonnull public static <T> ConvertedObject<T> ofNull()
      Creates a ConvertedObject containing null 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 only null.
    • ofNotConvertible

      @Nonnull public static <T> ConvertedObject<T> ofNotConvertible()
      Creates a ConvertedObject containing null 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 only null.
    • getObject

      @Nullable public T getObject()
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(@Nullable Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • 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.