- java.lang.Object
-
- swim.structure.Form<T>
-
- swim.structure.form.ClassForm<T>
-
- All Implemented Interfaces:
Cloneable
public final class ClassForm<T> extends Form<T> implements Cloneable
For someClass, a transformation between a structurally typedItemand an instance of thatClass.A
Classinstance in Java can be completely described by itsClassname, its field names, and its field values. This, combined with the fact that some fields are more important than others, gives rise to the following rules for transforming objects into structuredItems:- The String identifier for the
Class, usually simply theClassname or some function of it, is calledtag. - Every field being considered is either a
memberor aheader, with the latter reserved for "important" fields. - Every such field transforms to a
Slotwhose key is the name of the field and whose value is theItemrepresentation of the field. - The structural representation of every object is some
Recordunless the item isnull, which always transforms intoExtant. - The first entry in this
Recordis anAttrwhose key istagand whose value is either:- A
Recordofheadersthat were transformed intoSlotsvia rule 3., or Extantif thisClasshas no fields.
- A
- Every subsequent entry in the
Recordfrom rule 4. is amemberthat was transformed into aSlotvia rule 3.
These rules can be directly inverted to transform
Itemsto objects.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassForm<T>addHeader(Form<T> header)ClassForm<T>addMember(Form<T> member)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.ClassForm<T>clone()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.ClassForm<T>putHeader(String name, Form<?> form)ClassForm<T>putHeader(String name, Value key, Form<?> form)ClassForm<T>putHeader(Form<T> header)ClassForm<T>putMember(String name, Form<?> form)ClassForm<T>putMember(String name, Value key, Form<?> form)ClassForm<T>putMember(Form<T> member)Stringtag()Returns the key of the tag attribute that distinguishes structures of thisForm; returnsnullif thisFormhas no distinguishing tag attribute.ClassForm<T>tag(String tag)Class<?>type()Returns the reifiedClassof typeT.Tunit()Returns a default–possiblynull–value of typeT.ClassForm<T>unit(T unit)Returns a version of thisFormwith the givenunitvalue.-
Methods inherited from class swim.structure.Form
forArray, forBigInteger, forBoolean, forBuiltin, forByte, forByteBuffer, forCharacter, forClass, forClass, forCollection, forDouble, forFloat, forInteger, forItem, forList, forLong, forMap, forMap, forNumber, forSet, forShort, forString, forValue, isBuiltin
-
-
-
-
Method Detail
-
tag
public String tag()
Description copied from class:FormReturns 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()
Description copied from class:FormReturns a default–possiblynull–value of typeT. Used as the fallback return value whencoercingan invalid structural value.
-
unit
public ClassForm<T> unit(T unit)
Description copied from class:FormReturns a version of thisFormwith the givenunitvalue.
-
type
public Class<?> type()
Description copied from class:FormReturns the reifiedClassof typeT.
-
mold
public Item mold(T object, Item item)
Description copied from class:FormConverts 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 Item mold(T object)
Description copied from class:FormConverts a nominally typed Javaobjectinto its structurally typed equivalent. The returnedItemmust never benull.
-
cast
public T cast(Item item, T object)
Description copied from class:FormConverts 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 T cast(Item item)
Description copied from class:FormConverts a structurally typediteminto a nominally typed Java object. The passed-initemis assumed to be non-null.
-
-