Interface UnionObject


public interface UnionObject
A union object represents a boolean, char, byte, short, int, long, float, double, or Object. It is meant to provide a more strongly typed alternative in cases where Objects would otherwise be used.
  • Method Details

    • of

      static UnionObject of(boolean x)
    • of

      static UnionObject of(char x)
    • of

      static UnionObject of(byte x)
    • of

      static UnionObject of(short x)
    • of

      static UnionObject of(int x)
    • of

      static UnionObject of(long x)
    • of

      static UnionObject of(float x)
    • of

      static UnionObject of(double x)
    • of

      static UnionObject of(Object x)
      Create a wrapped object, must not be a boxed primitive type. Use from(Object) if you need boxed primitive support.
      Parameters:
      x - the object
      Returns:
      the union object
    • from

      static UnionObject from(Object x)
      If x is a boxed primitive, this will create the union object with the primitive value. Otherwise, this will create the object via of(Object).
      Parameters:
      x - the object
      Returns:
      the union object
    • unwrap

      Object unwrap()
      Unwraps the object or boxed primitive.
      Returns:
      the object
    • expect

      <T> T expect(Class<T> clazz) throws IllegalArgumentException
      Returns the object as type T if the unwrapped object is an instance of clazz.
      Type Parameters:
      T - the type
      Parameters:
      clazz - the class
      Returns:
      this object as type of clazz
      Throws:
      IllegalArgumentException - if the object is not an instance of clazz.
    • number

      Equivalent to expect(Number.class).
      Returns:
      this object as a Number
      Throws:
      IllegalArgumentException - if the object is not an instance of Number.
      See Also:
    • booleanValue

      boolean booleanValue()
      Equivalent to expect(Boolean.class).
      Returns:
      this object as a boolean
      See Also:
    • charValue

      char charValue()
      Equivalent to expect(Character.class).
      Returns:
      this object as a character
      See Also:
    • byteValue

      byte byteValue()
      Equivalent to number().byteValue().
      Returns:
      this object as a byte
      See Also:
    • shortValue

      short shortValue()
      Equivalent to number().shortValue().
      Returns:
      this object as a short
      See Also:
    • intValue

      int intValue()
      Equivalent to number().intValue().
      Returns:
      this object as an int
      See Also:
    • longValue

      long longValue()
      Equivalent to number().longValue().
      Returns:
      this object as a long
      See Also:
    • floatValue

      float floatValue()
      Equivalent to number().floatValue().
      Returns:
      this object as a float
      See Also:
    • doubleValue

      double doubleValue()
      Equivalent to number().doubleValue().
      Returns:
      this object as a double
      See Also:
    • visit

      <T> T visit(UnionObject.Visitor<T> visitor)