Class EmptyList
- All Implemented Interfaces:
ContainingType
,Type
,WrappingType
A special case of a list type, which is always empty. It is special, as it is co-variant with any other list, e.g. an empty list can be assigned to any other list type without upsetting type safety.
It wraps a list of type nothing, so that if you want to pretend it's a list, Type#find will do the right thing. Note that we return a list of type nothing so that if you attempt to use the member type, no equivalence or covariance is going to work for you
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionasStruct()
Attempt to convert the given value in to one represented by this type.int
estimateSize
(Object entry) Estimate the number of bytes used to serialize the given value to an output stream.Class<?>
The underlying java class used to represent this type.void
toBytes
(DataOutputStream os, Object toWrite) toString()
<T,
U> U visit
(TypeVisitor<T, U> tv, T data) Type specific visiting logic.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface nz.org.riskscape.engine.types.Type
checkForNull, find, findAllowNull, getUnwrappedType, isA, isNumeric, isWrapped, toString, unwrap
Methods inherited from interface nz.org.riskscape.engine.types.WrappingType
isNullable
-
Field Details
-
INSTANCE
The one and only instance of an EmptyList type
-
AS_STRUCT
-
-
Method Details
-
getContainedType
- Specified by:
getContainedType
in interfaceContainingType
- Returns:
- The type that this
ContainingType
contains.
-
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
- Specified by:
asStruct
in interfaceType
- Specified by:
asStruct
in interfaceWrappingType
-
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
- Specified by:
estimateSize
in interfaceWrappingType
- 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
- Specified by:
toBytes
in interfaceWrappingType
- Throws:
IOException
-
fromBytes
- Specified by:
fromBytes
in interfaceType
- Specified by:
fromBytes
in interfaceWrappingType
- Throws:
IOException
-
toString
-
visit
Description copied from interface:Type
Type specific visiting logic. Types must decide whether they are atomic or compound and call the relevant method on
TypeVisitor
. It's up to each compound type to decide how they want to structure their children, e.g. order, metadata, and what's considered a child or not.- Specified by:
visit
in interfaceContainingType
- Specified by:
visit
in interfaceType
- Specified by:
visit
in interfaceWrappingType
-
getUnderlyingType
- Specified by:
getUnderlyingType
in interfaceWrappingType
- Returns:
- the type that we immediately wrap. Used by
Type.getUnwrappedType()
to descend through all wrappedType
to find the first unwrapped one.
-