Package nz.org.riskscape.engine.types
Class Nullable
java.lang.Object
nz.org.riskscape.engine.types.Nullable
- All Implemented Interfaces:
ContainingType
,Type
Wraps another type to allow values to be null.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Nullable
static final Nullable
static final Nullable
static final Nullable
static final Nullable
static final Nullable
static final Nullable
static final Nullable
static final ComplexTypeConstructor
static final TypeInformation
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
asStruct()
Attempt to convert the given value in to one represented by this type.static Type
computeNullableAncestor
(Type lhs, Type rhs) Version ofTypes.computeAncestor(Type, Type)
that will give a nullable result if either type is itself nullableboolean
int
estimateSize
(Object entry) Estimate the number of bytes used to serialize the given value to an output stream.int
hashCode()
static Type
Class<?>
The underlying java class used to represent this type.static boolean
boolean
static Type
static Type
Apply a type-returning function to a type with null removed, applying nullable to the result if the given type was nullablestatic Type
void
toBytes
(DataOutputStream os, Object toWrite) toString()
static Type
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface nz.org.riskscape.engine.types.ContainingType
visit
Methods inherited from interface nz.org.riskscape.engine.types.Type
checkForNull, find, findAllowNull, getUnwrappedType, isA, isNumeric, isWrapped, toString, unwrap
-
Field Details
-
TYPE_CONSTRUCTOR
-
TYPE_INFORMATION
-
TEXT
-
BOOLEAN
-
INTEGER
-
FLOATING
-
DECIMAL
-
ANYTHING
-
DATE
-
GEOMETRY
-
-
Constructor Details
-
Nullable
-
-
Method Details
-
is
-
ifTrue
-
of
-
computeNullableAncestor
Version of
Types.computeAncestor(Type, Type)
that will give a nullable result if either type is itself nullable -
coerce
Description copied from interface:Type
Attempt to convert the given value in to one represented by this type.
- Specified by:
coerce
in interfaceType
- 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
Description copied from interface:Type
The underlying java class used to represent this type.
- Specified by:
internalType
in interfaceType
-
asStruct
-
hashCode
public int hashCode() -
equals
-
toString
-
estimateSize
Description copied from interface:Type
Estimate the number of bytes used to serialize the given value to an output stream.
- Specified by:
estimateSize
in interfaceType
- Parameters:
entry
- the value of this type to measure. Must be ofType.internalType()
or aClassCastException
is going to happen- Returns:
- the estimated number of bytes, or zero if no estimation was possible.
-
toBytes
- Specified by:
toBytes
in interfaceType
- Throws:
IOException
-
fromBytes
- Specified by:
fromBytes
in interfaceType
- Throws:
IOException
-
isNullable
public boolean isNullable()- Specified by:
isNullable
in interfaceType
- 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
- Returns:
- true if any of the given types are Nullable, e.g.
Type#find(Nullabe.class).isPresent()
is true
-
strip
-
unwrap
-
rewrap
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 nullablewrappingFunction
- 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
- Specified by:
getContainedType
in interfaceContainingType
- Returns:
- The type that this
ContainingType
contains.
-