Class JsonML


  • public class JsonML
    extends java.lang.Object
    Class which represents JsonML element according to the specification at "http://code.google.com/p/es-lab/wiki/JsonMLASTFormat"
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addChild​(int index, JsonML element)
      Inserts the given JsonML element at the given position in the list of children.
      void appendChild​(JsonML element)
      Appends a given child element to the list of children.
      void appendChildren​(java.util.Collection<? extends JsonML> elements)
      Appends a collection of children to the back of the list of children.
      int childrenSize()
      Returns number of the children.
      void clearChildren()
      Removes all elements from the list of children.
      java.lang.Object getAttribute​(TagAttr name)
      Returns value associated with a given attribute.
      java.util.Map<TagAttr,​java.lang.Object> getAttributes()
      Returns a map with attributes and respective values.
      JsonML getChild​(int index)
      Returns child at a given position.
      java.util.List<JsonML> getChildren()
      Returns a list of all children.
      java.util.List<JsonML> getChildren​(int fromIndex, int toIndex)
      Returns the portion of children list between the specified fromIndex, inclusive, and toIndex, exclusive.
      TagType getType()
      Returns type of the JsonML element.
      boolean hasChildren()
      Returns true if the JsonML element has at least one child.
      void setAttribute​(TagAttr name, java.lang.Object value)
      Sets value for a given attribute.
      void setAttributes​(java.util.Map<TagAttr,​java.lang.Object> attributes)
      Sets attributes of the JsonML element.
      void setChild​(int index, JsonML element)
      Replaces the element at the given position in the list of children wit the given JsonML element.
      void setChildren​(JsonML... children)
      Replaces all elements in the list of children with the given JsonML elements.
      void setChildren​(java.util.List<JsonML> children)
      Replaces all elements in the list of children with the given list of JsonML elements..
      java.lang.String toString()  
      java.lang.String toStringTree()
      Prints a JsonML tree in a human readable format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JsonML

        public JsonML​(TagType type)
        Creates a new element with a given type.
        Parameters:
        type -
      • JsonML

        public JsonML​(TagType type,
                      JsonML... children)
        Creates a new element.
        Parameters:
        type - type of the element
        children - children to append to the element
      • JsonML

        public JsonML​(TagType type,
                      java.util.List<? extends JsonML> children)
      • JsonML

        public JsonML​(TagType type,
                      java.util.Map<? extends TagAttr,​?> attributes)
      • JsonML

        public JsonML​(TagType type,
                      java.util.Map<? extends TagAttr,​?> attributes,
                      java.util.List<? extends JsonML> children)
    • Method Detail

      • addChild

        public void addChild​(int index,
                             JsonML element)
        Inserts the given JsonML element at the given position in the list of children.
        Parameters:
        index - index at which the given element is to be inserted
        element - JsonML element to be inserted
      • appendChild

        public void appendChild​(JsonML element)
        Appends a given child element to the list of children.
        Parameters:
        element - JsonML element to append
      • appendChildren

        public void appendChildren​(java.util.Collection<? extends JsonML> elements)
        Appends a collection of children to the back of the list of children.
        Parameters:
        elements - collection of JsonML elements to append
      • childrenSize

        public int childrenSize()
        Returns number of the children.
      • clearChildren

        public void clearChildren()
        Removes all elements from the list of children.
      • getAttribute

        public java.lang.Object getAttribute​(TagAttr name)
        Returns value associated with a given attribute.
        Parameters:
        name - name of the attribute
        Returns:
        associated value or null if the attribute is not present
      • getAttributes

        public java.util.Map<TagAttr,​java.lang.Object> getAttributes()
        Returns a map with attributes and respective values.
      • getChild

        public JsonML getChild​(int index)
        Returns child at a given position.
      • getChildren

        public java.util.List<JsonML> getChildren()
        Returns a list of all children.
      • getChildren

        public java.util.List<JsonML> getChildren​(int fromIndex,
                                                  int toIndex)
        Returns the portion of children list between the specified fromIndex, inclusive, and toIndex, exclusive.
        Parameters:
        fromIndex - low endpoint (inclusive)
        toIndex - high endpoint (exclusive)
      • getType

        public TagType getType()
        Returns type of the JsonML element.
      • hasChildren

        public boolean hasChildren()
        Returns true if the JsonML element has at least one child.
      • setAttribute

        public void setAttribute​(TagAttr name,
                                 java.lang.Object value)
        Sets value for a given attribute.
        Parameters:
        name - name of the attribute
        value - value to associate with the attribute
      • setAttributes

        public void setAttributes​(java.util.Map<TagAttr,​java.lang.Object> attributes)
        Sets attributes of the JsonML element.
        Parameters:
        attributes - map with attributes and their values
      • setChild

        public void setChild​(int index,
                             JsonML element)
        Replaces the element at the given position in the list of children wit the given JsonML element.
        Parameters:
        index - index of element to replace
        element - JsonML element to append
      • setChildren

        public void setChildren​(JsonML... children)
        Replaces all elements in the list of children with the given JsonML elements.
        Parameters:
        children - a comma separated list of JsonML elements
      • setChildren

        public void setChildren​(java.util.List<JsonML> children)
        Replaces all elements in the list of children with the given list of JsonML elements..
        Parameters:
        children - a list of JsonML elements.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringTree

        public java.lang.String toStringTree()
        Prints a JsonML tree in a human readable format.