- java.lang.Object
-
- swim.structure.Form<T>
-
- Direct Known Subclasses:
ArrayForm
,BigIntegerForm
,BooleanForm
,ByteBufferForm
,ByteForm
,CharacterForm
,ClassForm
,CollectionForm
,DoubleForm
,FieldForm
,FloatForm
,IntegerForm
,ItemForm
,LongForm
,MapForm
,NumberForm
,PolyForm
,R2Form
,R3Form
,ShortForm
,StringForm
,TagForm
,TensorForm
,UnitForm
,UriForm
,UriPathForm
,UriPatternForm
,ValueForm
,Z2Form
,Z3Form
public abstract class Form<T> extends Object
Transformation between a structurally typedItem
and a nominally typed Java object.
-
-
Constructor Summary
Constructors Constructor Description Form()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract T
cast(Item item)
Converts a structurally typeditem
into a nominally typed Java object.T
cast(Item item, T object)
Converts a structurally typeditem
into a nominally typed Java object based on the provided prototypeobject
.static <T> Form<T>
forArray(Class<?> type, Form<?> form)
Utility method to construct anArrayForm
.static Form<BigInteger>
forBigInteger()
Utility method to receive a singletonBigIntegerForm
.static Form<Boolean>
forBoolean()
Utility method to receive a singletonBooleanForm
.static <T> Form<T>
forBuiltin(Class<?> type)
Returns thetype
built-inForm
fortype
if it exists, andnull
if it does not.static Form<Byte>
forByte()
Utility method to receive a singletonByteForm
.static Form<ByteBuffer>
forByteBuffer()
Utility method to receive a singletonByteBufferForm
.static Form<Character>
forCharacter()
Utility method to receive a singletonCharacterForm
.static <T> Form<T>
forClass(Class<?> type)
static <T> Form<T>
forClass(Class<?> type, PolyForm scope)
Returns aForm
fortype
againstscope
preferring built-inForms
toClassForm
constructions whenever possible.static <CC,T>
Form<CC>forCollection(Class<?> type, Form<T> form)
Utility method to construct aCollectionForm
.static Form<Double>
forDouble()
Utility method to receive a singletonDoubleForm
.static Form<Float>
forFloat()
Utility method to receive a singletonFloatForm
.static Form<Integer>
forInteger()
Utility method to receive a singletonIntegerForm
.static Form<Item>
forItem()
Utility method to receive a singletonItemForm
.static <T> Form<List<T>>
forList(Form<T> form)
Utility method to construct aCollectionForm
where the underlying collection is of typeList<T>
.static Form<Long>
forLong()
Utility method to receive a singletonLongForm
.static <CC,K,V>
Form<CC>forMap(Class<?> type, Form<K> keyForm, Form<V> valForm)
static <K,V>
Form<Map<K,V>>forMap(Form<K> keyForm, Form<V> valForm)
Utility method to construct aMapForm
.static Form<Number>
forNumber()
Utility method to receive a singletonNumberForm
.static <T> Form<Set<T>>
forSet(Form<T> form)
Utility method to construct aCollectionForm
where the underlying collection is of typeList<T>
.static Form<Short>
forShort()
Utility method to receive a singletonShortForm
.static Form<String>
forString()
Utility method to receive a singletonStringForm
.static Form<Value>
forValue()
Utility method to receive a singletonValueForm
.static boolean
isBuiltin(Class<?> type)
Returns whethertype
has a built-in base (i.e.abstract Item
mold(T object)
Converts a nominally typed Javaobject
into its structurally typed equivalent.Item
mold(T object, Item item)
Converts a nominally typed Javaobject
into its structurally typed equivalent based on the provided prototypeitem
.String
tag()
Returns the key of the tag attribute that distinguishes structures of thisForm
; returnsnull
if thisForm
has no distinguishing tag attribute.Form<T>
tag(String tag)
abstract Class<?>
type()
Returns the reifiedClass
of typeT
.T
unit()
Returns a default–possiblynull
–value of typeT
.Form<T>
unit(T unit)
Returns a version of thisForm
with the givenunit
value.
-
-
-
Method Detail
-
tag
public String tag()
Returns the key of the tag attribute that distinguishes structures of thisForm
; returnsnull
if thisForm
has no distinguishing tag attribute. Used to accelerate distrcrimination of polymorphic structural types with nominal type hints.
-
unit
public T unit()
Returns a default–possiblynull
–value of typeT
. Used as the fallback return value whencoercing
an invalid structural value.
-
type
public abstract Class<?> type()
Returns the reifiedClass
of typeT
.
-
mold
public Item mold(T object, Item item)
Converts a nominally typed Javaobject
into its structurally typed equivalent based on the provided prototypeitem
. The passed-initem
is assumed to be non-null
. The returnedItem
must never benull
.
-
mold
public abstract Item mold(T object)
Converts a nominally typed Javaobject
into its structurally typed equivalent. The returnedItem
must never benull
.
-
cast
public T cast(Item item, T object)
Converts a structurally typeditem
into a nominally typed Java object based on the provided prototypeobject
. The passed-initem
is assumed to be non-null
. The passed-in prototypeobject
may benull
.
-
cast
public abstract T cast(Item item)
Converts a structurally typeditem
into a nominally typed Java object. The passed-initem
is assumed to be non-null
.
-
forInteger
public static Form<Integer> forInteger()
Utility method to receive a singletonIntegerForm
.
-
forDouble
public static Form<Double> forDouble()
Utility method to receive a singletonDoubleForm
.
-
forCharacter
public static Form<Character> forCharacter()
Utility method to receive a singletonCharacterForm
.
-
forBoolean
public static Form<Boolean> forBoolean()
Utility method to receive a singletonBooleanForm
.
-
forBigInteger
public static final Form<BigInteger> forBigInteger()
Utility method to receive a singletonBigIntegerForm
.
-
forNumber
public static Form<Number> forNumber()
Utility method to receive a singletonNumberForm
.
-
forString
public static Form<String> forString()
Utility method to receive a singletonStringForm
.
-
forByteBuffer
public static Form<ByteBuffer> forByteBuffer()
Utility method to receive a singletonByteBufferForm
.
-
forArray
public static <T> Form<T> forArray(Class<?> type, Form<?> form)
Utility method to construct anArrayForm
.
-
forCollection
public static <CC,T> Form<CC> forCollection(Class<?> type, Form<T> form)
Utility method to construct aCollectionForm
.
-
forList
public static <T> Form<List<T>> forList(Form<T> form)
Utility method to construct aCollectionForm
where the underlying collection is of typeList<T>
.
-
forSet
public static <T> Form<Set<T>> forSet(Form<T> form)
Utility method to construct aCollectionForm
where the underlying collection is of typeList<T>
.
-
forMap
public static <CC,K,V> Form<CC> forMap(Class<?> type, Form<K> keyForm, Form<V> valForm)
- Throws:
ClassCastException
- iftype
does not extendMap
-
forMap
public static <K,V> Form<Map<K,V>> forMap(Form<K> keyForm, Form<V> valForm)
Utility method to construct aMapForm
.
-
isBuiltin
public static boolean isBuiltin(Class<?> type)
Returns whethertype
has a built-in base (i.e. is defined inswim.structure.form
and is not aCollectionForm
)Form
.
-
forBuiltin
public static <T> Form<T> forBuiltin(Class<?> type)
Returns thetype
built-inForm
fortype
if it exists, andnull
if it does not.
-
forClass
public static <T> Form<T> forClass(Class<?> type, PolyForm scope)
Returns aForm
fortype
againstscope
preferring built-inForms
toClassForm
constructions whenever possible.
-
-