Package nz.org.riskscape.engine.types
Class WithMetadata
java.lang.Object
nz.org.riskscape.engine.types.WithMetadata
- All Implemented Interfaces:
Type
,WrappingType
Wrapping type that stores extra metadata along with a given type. For example,
this lets you potentially store the expression that created the type (e.g.
bookmark('foo')
), along with the type itself (e.g. RelationType
.
Multiple metadata objects can be associated with the underlying type. We assume that each metadata object is of a unique class, but this is not enforced at all.
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Attempt to convert the given value in to one represented by this type.boolean
static <T> Optional<T>
<T> Optional<T>
getMetadata
(Class<T> target) int
hashCode()
Class<?>
The underlying java class used to represent this type.toString()
static Type
Creates a new WithMetadata that wraps the given type and associates the metadata with itMethods inherited from class java.lang.Object
clone, finalize, getClass, 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
asStruct, estimateSize, fromBytes, isNullable, toBytes, visit
-
Method Details
-
wrap
Creates a new WithMetadata that wraps the given type and associates the metadata with it
-
find
- Returns:
- metadata matching the class given, if any
-
getMetadata
- Returns:
- metadata of the given target class, if any. If there are multiple metadata objects that match (e.g. Identified), then the first match found is returned
-
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
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode() -
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.
-