Class ArcheTextObject


  • public class ArcheTextObject
    extends Object
    The object representation for all ArcheText objects and values. ArcheText objects have types and can inherit values from one or more objects.
    Author:
    Matthew Tropiano
    • Constructor Detail

      • ArcheTextObject

        public ArcheTextObject()
        Creates a new anonymous ArcheTextObject.
      • ArcheTextObject

        public ArcheTextObject​(String type)
        Creates a new default ArcheTextObject with a type.
        Parameters:
        type - the object type name.
      • ArcheTextObject

        public ArcheTextObject​(String type,
                               String identity)
        Creates a new ArcheTextObject with a type and identity.
        Parameters:
        type - the object type name.
        identity - the object's identity.
    • Method Detail

      • getType

        public String getType()
        Returns:
        the type name of this object.
      • getIdentity

        public String getIdentity()
        Returns:
        the identity of this object.
      • getParents

        public Iterable<ArcheTextObject> getParents()
        Returns:
        an Iterable of the object's parents, in order of precedence.
      • isAnonymous

        public boolean isAnonymous()
        Returns:
        true if this object has no type nor name, false otherwise.
      • isDefault

        public boolean isDefault()
        Returns:
        true if this object has a type but no name, false otherwise.
      • pushParent

        public void pushParent​(ArcheTextObject parent)
        Pushes a parent onto the top of the parent stack. The new parent is now the highest priority for inheritance.
        Parameters:
        parent - the parent to push.
      • addParent

        public void addParent​(ArcheTextObject parent)
        Adds a parent to this object. The new parent is now the lowest priority for inheritance.
        Parameters:
        parent - the parent to add.
      • removeParent

        public boolean removeParent​(ArcheTextObject parent)
        Removes a parent from the parent stack.
        Parameters:
        parent - the parent to remove.
        Returns:
        true if removed.
      • set

        public void set​(String name,
                        Object value)
        Sets the value of a field. Equivalent to setField(name, Combinator.SET, value).
        Parameters:
        name - the name of the field to set.
        value - the value of the field.
      • set

        public void set​(String name,
                        Combinator combinator,
                        Object value)
        Sets the value of a field.
        Parameters:
        name - the name of the field to set.
        combinator - the value combinator for field inheritance.
        value - the value of the field.
      • clear

        public void clear​(String name)
        Clears the value of a field.
        Parameters:
        name - the name of the field to clear.
      • containsLocal

        public boolean containsLocal​(String name)
        Returns true if this object (and only this object) contains a field.
        Parameters:
        name - the name of the field.
        Returns:
        true if so, false if not.
      • getLocal

        public <T> T getLocal​(String name,
                              Class<T> outputType)
        Gets the value of a local field. The field's value is taken from THIS OBJECT, not its parents.
        Type Parameters:
        T - the return type.
        Parameters:
        name - the name of the field.
        outputType - the output type to convert to.
        Returns:
        the value converted to the desired type.
      • get

        public Object get​(String name)
        Gets the value of a field, searching through its lineage if it doesn't exist in this one, combining values as necessary.
        Parameters:
        name - the name of the field.
        Returns:
        the value, as an object.
      • get

        public <T> T get​(String name,
                         Class<T> outputType)
        Gets the value of a field, searching through its lineage if it doesn't exist in this one, combining values as necessary.
        Type Parameters:
        T - the return type.
        Parameters:
        name - the name of the field.
        outputType - the output type to convert to.
        Returns:
        the value converted to the desired type.
      • cascade

        public void cascade​(ArcheTextObject addend)
        Adds the fields and lineage from another object to this object. NOTE: Field Combinators from the object getting added come into effect when setting the values in this object.
        Parameters:
        addend - the object to add to this one.
      • flatten

        public void flatten()
        Flattens the hierarchy of this object, such that it has no parent references and its fields are all SET fields with the hierarchically-calculated results. This object's contents will be changed. The parents themselves are not changed.
      • getAvailableFieldNames

        public Set<String> getAvailableFieldNames()
        Returns all possible field names in this object's lineage.
        Returns:
        an array of every field name.
      • newObject

        public <T> T newObject​(Class<T> clazz)
        Converts the contents of this object to a new instance of an object bean / plain ol' Java object.

        This object is applied via the target object's public fields and setter methods.

        For instance, if there is a member on this object called "color", its value will be applied via the public field "color" or the setter "setColor()". Public fields take precedence over setters.

        Type Parameters:
        T - the return type.
        Parameters:
        clazz - the output class type.
        Returns:
        the new object.
      • applyToObject

        public <T> T applyToObject​(T object)
        Applies this object to an object bean / plain ol' Java object.

        This object is applied via the target object's public fields and setter methods.

        For instance, if there is a member on this object called "color", its value will be applied via the public field "color" or the setter "setColor()". Public fields take precedence over setters.

        Type Parameters:
        T - the return type.
        Parameters:
        object - the target object.
        Returns:
        the applied object itself.
      • fieldNameIterator

        public Iterator<String> fieldNameIterator()
        Returns:
        a field name iterator for this object (only local fields).