Class ClassForm<T>

  • All Implemented Interfaces:
    Cloneable

    public final class ClassForm<T>
    extends Form<T>
    implements Cloneable
    For some Class, a transformation between a structurally typed Item and an instance of that Class.

    A Class instance in Java can be completely described by its Class 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 structured Items:

    1. The String identifier for the Class, usually simply the Class name or some function of it, is called tag.
    2. Every field being considered is either a member or a header, with the latter reserved for "important" fields.
    3. Every such field transforms to a Slot whose key is the name of the field and whose value is the Item representation of the field.
    4. The structural representation of every object is some Record unless the item is null, which always transforms into Extant.
    5. The first entry in this Record is an Attr whose key is tag and whose value is either:
      • A Record of headers that were transformed into Slots via rule 3., or
      • Extant if this Class has no fields.
    6. Every subsequent entry in the Record from rule 4. is a member that was transformed into a Slot via rule 3.

    These rules can be directly inverted to transform Items to objects.

    • Constructor Detail

      • ClassForm

        public ClassForm​(Class<?> type,
                         String tag,
                         T unit)
    • Method Detail

      • tag

        public String tag()
        Description copied from class: Form
        Returns the key of the tag attribute that distinguishes structures of this Form; returns null if this Form has no distinguishing tag attribute. Used to accelerate distrcrimination of polymorphic structural types with nominal type hints.
        Overrides:
        tag in class Form<T>
      • tag

        public ClassForm<T> tag​(String tag)
        Description copied from class: Form
        Returns a version of this Form that requires a head Attr with the given tag name.
        Overrides:
        tag in class Form<T>
      • unit

        public T unit()
        Description copied from class: Form
        Returns a default–possibly null–value of type T. Used as the fallback return value when coercing an invalid structural value.
        Overrides:
        unit in class Form<T>
      • unit

        public ClassForm<T> unit​(T unit)
        Description copied from class: Form
        Returns a version of this Form with the given unit value.
        Overrides:
        unit in class Form<T>
      • type

        public Class<?> type()
        Description copied from class: Form
        Returns the reified Class of type T.
        Specified by:
        type in class Form<T>
      • mold

        public Item mold​(T object,
                         Item item)
        Description copied from class: Form
        Converts a nominally typed Java object into its structurally typed equivalent based on the provided prototype item. The passed-in item is assumed to be non-null. The returned Item must never be null.
        Overrides:
        mold in class Form<T>
      • mold

        public Item mold​(T object)
        Description copied from class: Form
        Converts a nominally typed Java object into its structurally typed equivalent. The returned Item must never be null.
        Specified by:
        mold in class Form<T>
      • cast

        public T cast​(Item item,
                      T object)
        Description copied from class: Form
        Converts a structurally typed item into a nominally typed Java object based on the provided prototype object. The passed-in item is assumed to be non-null. The passed-in prototype object may be null.
        Overrides:
        cast in class Form<T>
      • cast

        public T cast​(Item item)
        Description copied from class: Form
        Converts a structurally typed item into a nominally typed Java object. The passed-in item is assumed to be non-null.
        Specified by:
        cast in class Form<T>