- 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 typedItemand 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 Tcast(Item item)Converts a structurally typediteminto a nominally typed Java object.Tcast(Item item, T object)Converts a structurally typediteminto 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 thetypebuilt-inFormfortypeif it exists, andnullif 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 aFormfortypeagainstscopepreferring built-inFormstoClassFormconstructions 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 aCollectionFormwhere 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 aCollectionFormwhere 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 booleanisBuiltin(Class<?> type)Returns whethertypehas a built-in base (i.e.abstract Itemmold(T object)Converts a nominally typed Javaobjectinto its structurally typed equivalent.Itemmold(T object, Item item)Converts a nominally typed Javaobjectinto its structurally typed equivalent based on the provided prototypeitem.Stringtag()Returns the key of the tag attribute that distinguishes structures of thisForm; returnsnullif thisFormhas no distinguishing tag attribute.Form<T>tag(String tag)abstract Class<?>type()Returns the reifiedClassof typeT.Tunit()Returns a default–possiblynull–value of typeT.Form<T>unit(T unit)Returns a version of thisFormwith the givenunitvalue.
-
-
-
Method Detail
-
tag
public String tag()
Returns the key of the tag attribute that distinguishes structures of thisForm; returnsnullif thisFormhas 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 whencoercingan invalid structural value.
-
type
public abstract Class<?> type()
Returns the reifiedClassof typeT.
-
mold
public Item mold(T object, Item item)
Converts a nominally typed Javaobjectinto its structurally typed equivalent based on the provided prototypeitem. The passed-initemis assumed to be non-null. The returnedItemmust never benull.
-
mold
public abstract Item mold(T object)
Converts a nominally typed Javaobjectinto its structurally typed equivalent. The returnedItemmust never benull.
-
cast
public T cast(Item item, T object)
Converts a structurally typediteminto a nominally typed Java object based on the provided prototypeobject. The passed-initemis assumed to be non-null. The passed-in prototypeobjectmay benull.
-
cast
public abstract T cast(Item item)
Converts a structurally typediteminto a nominally typed Java object. The passed-initemis 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 aCollectionFormwhere the underlying collection is of typeList<T>.
-
forSet
public static <T> Form<Set<T>> forSet(Form<T> form)
Utility method to construct aCollectionFormwhere 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- iftypedoes 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 whethertypehas a built-in base (i.e. is defined inswim.structure.formand is not aCollectionForm)Form.
-
forBuiltin
public static <T> Form<T> forBuiltin(Class<?> type)
Returns thetypebuilt-inFormfortypeif it exists, andnullif it does not.
-
forClass
public static <T> Form<T> forClass(Class<?> type, PolyForm scope)
Returns aFormfortypeagainstscopepreferring built-inFormstoClassFormconstructions whenever possible.
-
-