Class Nullable

java.lang.Object
nz.org.riskscape.engine.types.Nullable
All Implemented Interfaces:
ContainingType, Type

public class Nullable extends Object implements Type, ContainingType

Wraps another type to allow values to be null.

  • Field Details

    • TYPE_CONSTRUCTOR

      public static final ComplexTypeConstructor TYPE_CONSTRUCTOR
    • TYPE_INFORMATION

      public static final TypeInformation TYPE_INFORMATION
    • TEXT

      public static final Nullable TEXT
    • BOOLEAN

      public static final Nullable BOOLEAN
    • INTEGER

      public static final Nullable INTEGER
    • FLOATING

      public static final Nullable FLOATING
    • DECIMAL

      public static final Nullable DECIMAL
    • ANYTHING

      public static final Nullable ANYTHING
    • DATE

      public static final Nullable DATE
    • GEOMETRY

      public static final Nullable GEOMETRY
  • Constructor Details

    • Nullable

      protected Nullable(Type wrapped)
  • Method Details

    • is

      public static boolean is(Type toCheck)
    • ifTrue

      public static Type ifTrue(boolean flag, Type wrapped)
    • of

      public static Type of(Type wrapped)
    • computeNullableAncestor

      public static Type computeNullableAncestor(Type lhs, Type rhs)

      Version of Types.computeAncestor(Type, Type) that will give a nullable result if either type is itself nullable

    • coerce

      public Object coerce(Object value) throws CoercionException
      Description copied from interface: Type

      Attempt to convert the given value in to one represented by this type.

      Specified by:
      coerce in interface Type
      Parameters:
      value - The value to coerce
      Returns:
      A value that conforms to this type
      Throws:
      CoercionException - if the given object can not be converted to something represented by this type
    • internalType

      public Class<?> internalType()
      Description copied from interface: Type

      The underlying java class used to represent this type.

      Specified by:
      internalType in interface Type
    • asStruct

      public Struct asStruct()
      Specified by:
      asStruct in interface Type
    • hashCode

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

      public boolean equals(Object rhs)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • estimateSize

      public int estimateSize(Object entry)
      Description copied from interface: Type

      Estimate the number of bytes used to serialize the given value to an output stream.

      Specified by:
      estimateSize in interface Type
      Parameters:
      entry - the value of this type to measure. Must be of Type.internalType() or a ClassCastException is going to happen
      Returns:
      the estimated number of bytes, or zero if no estimation was possible.
    • toBytes

      public void toBytes(DataOutputStream os, Object toWrite) throws IOException
      Specified by:
      toBytes in interface Type
      Throws:
      IOException
    • fromBytes

      public Object fromBytes(DataInputStream in) throws IOException
      Specified by:
      fromBytes in interface Type
      Throws:
      IOException
    • isNullable

      public boolean isNullable()
      Specified by:
      isNullable in interface Type
      Returns:
      true if this type can be set to nothing TODO this might need to be final and do an instanceof check somewhere - we always want nullable to be on the outside
    • any

      public static boolean any(Type... types)
      Returns:
      true if any of the given types are Nullable, e.g. Type#find(Nullabe.class).isPresent() is true
    • strip

      public static Type strip(Type mightBeNullable)
    • unwrap

      public static Type unwrap(Type mightBeNullable)
    • rewrap

      public static Type rewrap(Type mightBeNullable, Function<Type,Type> wrappingFunction)

      Apply a type-returning function to a type with null removed, applying nullable to the result if the given type was nullable

      Parameters:
      mightBeNullable - a type, possible nullable
      wrappingFunction - a function to apply to the non-nullable part of mightBeNullable
      Returns:
      the result of the wrappingFunction, surrounded by a nullable type if mightBeNullable was nullable
    • getContainedType

      public Type getContainedType()
      Specified by:
      getContainedType in interface ContainingType
      Returns:
      The type that this ContainingType contains.