Interface Type
- All Known Subinterfaces:
ContainingType
,Rangeable
,WrappingType
- All Known Implementing Classes:
Anything
,Bool
,CanonicalType
,CoverageType
,Date
,Decimal
,EmptyList
,Enumeration
,Floating
,FunctionType
,Geom
,GeomType
,GeomType.Line
,GeomType.Point
,GeomType.Polygon
,IdentifiedType
,Integer
,LambdaType
,LinkedType
,LookupTableType
,MultiGeom
,Nothing
,Nullable
,OfUnit
,Referenced
,RelationType
,RSList
,ScopedLambdaType
,SimpleType
,Struct
,Text
,WithinRange
,WithinSet
,WithMetadata
The root interface for Riskscape's type system. Each instance of type offers a coerce method for checking that a given object corresponds to the type.
-
Method Summary
Modifier and TypeMethodDescriptionasStruct()
default void
checkForNull
(Object value) 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.Type-safe way to find a particular Type by recursing through this type and any types that it wraps.findAllowNull
(Class<T> type) Convenience forNullable.strip(this).find(type)
default Type
Class<?>
The underlying java class used to represent this type.default <T extends Type>
booleandefault boolean
default boolean
Indicates if thisType
is numeric.default boolean
void
toBytes
(DataOutputStream os, Object toWrite) default String
A Riskscape specific toString of the given value, as an alternative to the java type's native toString representation.unwrap()
<T,
U> U visit
(TypeVisitor<T, U> tv, T data) Type specific visiting logic.
-
Method Details
-
coerce
Attempt to convert the given value in to one represented by this 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
Class<?> internalType()The underlying java class used to represent this type.
-
isNumeric
default boolean isNumeric()- Returns:
- true is this Type is a numeric type
-
checkForNull
-
getUnwrappedType
- Returns:
- the first type that actually holds the value (and is not just adding type metadata)
-
find
Type-safe way to find a particular Type by recursing through this type and any types that it wraps. This doesn't (and shouldn't) consider types with member types, such as structs and lists - this is meant as a more sound method of doing instanceof, considering
WrappingType
s -
findAllowNull
Convenience for
Nullable.strip(this).find(type)
-
isA
-
isWrapped
default boolean isWrapped()- Returns:
- true if this type is a wrapping type
-
asStruct
Struct asStruct() -
estimateSize
Estimate the number of bytes used to serialize the given value to an output stream.
- Parameters:
entry
- the value of this type to measure. Must be ofinternalType()
or aClassCastException
is going to happen- Returns:
- the estimated number of bytes, or zero if no estimation was possible.
-
toBytes
- Throws:
IOException
-
fromBytes
- Throws:
IOException
-
isNullable
default boolean isNullable()- 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
-
toString
A Riskscape specific toString of the given value, as an alternative to the java type's native toString representation.
-
unwrap
- Returns:
- a
List
of all the types that are wrapped by this type, including this one, in depth-first-search order. This will mean the simple unwrapped type is the first element of the list.
-
visit
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.
-