Class Struct
- All Implemented Interfaces:
Type
Permissive struct-like type that allows a c-like struct (like a java class with only fields) to be declared with members being other riskscape types.
Struct should be constructed using the builder. eg:
java
Struct.of("name", Types.TEXT).and("value", Types.INTEGER).build();
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class for constructing struct types with a fluid apistatic final class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Struct
static final Class<?>
static final TypeInformation
-
Method Summary
Modifier and TypeMethodDescriptionReturns this with the extra member added on TODO using some kind of optimized copying immutable map might cut down on garbage collection etc (if guava isn't already doing that)addOrReplace
(String key, Type type) Synonym ofadd(String, Type)
to support change in builder APISynonym ofadd(String, Type)
to support change in builder APIasStruct()
build()
Deprecated.static Struct.StructBuilder
builder()
Attempt to convert the given value in to one represented by this type.boolean
contains
(Struct.StructMember entry) boolean
int
estimateSize
(Object entry) Estimate the number of bytes used to serialize the given value to an output stream.flattenMemberKeys
(Struct struct) null-returning variation of getMember TODO consider making this package level or change it's name or somethingint
hashCode()
boolean
Class<?>
The underlying java class used to represent this type.boolean
isEquivalent
(Struct rhs) boolean
isSupersetOf
(Struct rhs) boolean
static Struct
of()
Create an empty structstatic Struct
Define a struct, starting with the given key and typestatic Struct
static Struct
static Struct
static Struct
of
(String k0, Type t0, String k1, Type t1, String k2, Type t2, String k3, Type t3, String k4, Type t4) int
size()
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, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface nz.org.riskscape.engine.types.Type
checkForNull, find, findAllowNull, getUnwrappedType, isA, isNullable, isNumeric, isWrapped, toString, unwrap
-
Field Details
-
INTERNAL_TYPE
-
TYPE_INFORMATION
-
EMPTY_STRUCT
-
-
Method Details
-
of
Create an empty struct
-
of
Define a struct, starting with the given key and type
- Returns:
- a builder to use to define the struct.
-
of
-
of
-
of
-
of
-
builder
-
flattenMemberKeys
- Returns:
- a list of member keys in DFS order, where children have their key appended to their parent's with a dot
between them, so they are in the style a user would enter in an expression, e.g.
foo.bar
-
getMemberKeys
- Returns:
- a
List
of the names/keys of all the members in this struct, sorted alphabetically.
-
getMembers
-
coerce
Description copied from interface:Type
Attempt to convert the given value in to one represented by this type.
-
internalType
Description copied from interface:Type
The underlying java class used to represent this type.
- Specified by:
internalType
in interfaceType
-
build
Deprecated.Compatability shim to cope with API change to Struct.of/Struct.and
-
toString
-
getMember
- Returns:
- a StructMember identified by the given key, or Optional.empty() if non exists
-
getEntry
null-returning variation of getMember TODO consider making this package level or change it's name or something
-
parent
-
add
Returns this with the extra member added on TODO using some kind of optimized copying immutable map might cut down on garbage collection etc (if guava isn't already doing that)
-
replace
- Returns:
- a new Struct with the given member replaced with one of a new type.
-
and
Synonym of
add(String, Type)
to support change in builder API -
and
Synonym of
add(String, Type)
to support change in builder API -
asStruct
-
size
public int size() -
contains
-
isUnion
- Returns:
- true if the two structs have the same ordered list of member types - e.g. their tuples could be combined in a union
-
isEquivalent
- Returns:
- true if the two structs have the same members, considering only the keys and the types.
-
isSupersetOf
- Returns:
- true if this struct is a superset, that is contains at least the same members as rhs.
-
hasMember
-
hashCode
public int hashCode() -
equals
-
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
-
addOrReplace
-
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.
-