- 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 typedItem
and an instance of thatClass
.A
Class
instance in Java can be completely described by itsClass
name, 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 theClass
name or some function of it, is calledtag
. - Every field being considered is either a
member
or aheader
, with the latter reserved for "important" fields. - Every such field transforms to a
Slot
whose key is the name of the field and whose value is theItem
representation of the field. - The structural representation of every object is some
Record
unless the item isnull
, which always transforms intoExtant
. - The first entry in this
Record
is anAttr
whose key istag
and whose value is either:- A
Record
ofheaders
that were transformed intoSlots
via rule 3., or Extant
if thisClass
has no fields.
- A
- Every subsequent entry in the
Record
from rule 4. is amember
that was transformed into aSlot
via rule 3.
These rules can be directly inverted to transform
Items
to 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)
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
.ClassForm<T>
clone()
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
.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)
String
tag()
Returns the key of the tag attribute that distinguishes structures of thisForm
; returnsnull
if thisForm
has no distinguishing tag attribute.ClassForm<T>
tag(String tag)
Class<?>
type()
Returns the reifiedClass
of typeT
.T
unit()
Returns a default–possiblynull
–value of typeT
.ClassForm<T>
unit(T unit)
Returns a version of thisForm
with the givenunit
value.-
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:Form
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()
Description copied from class:Form
Returns a default–possiblynull
–value of typeT
. Used as the fallback return value whencoercing
an invalid structural value.
-
unit
public ClassForm<T> unit(T unit)
Description copied from class:Form
Returns a version of thisForm
with the givenunit
value.
-
type
public Class<?> type()
Description copied from class:Form
Returns the reifiedClass
of typeT
.
-
mold
public Item mold(T object, Item item)
Description copied from class:Form
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 Item mold(T object)
Description copied from class:Form
Converts a nominally typed Javaobject
into its structurally typed equivalent. The returnedItem
must never benull
.
-
cast
public T cast(Item item, T object)
Description copied from class:Form
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 T cast(Item item)
Description copied from class:Form
Converts a structurally typeditem
into a nominally typed Java object. The passed-initem
is assumed to be non-null
.
-
-