com.google.clearsilver.jsilver.data
Class NestedMapData

java.lang.Object
  extended by com.google.clearsilver.jsilver.data.AbstractData
      extended by com.google.clearsilver.jsilver.data.NestedMapData
All Implemented Interfaces:
Data
Direct Known Subclasses:
DefaultData

public class NestedMapData
extends AbstractData

Represents a hierarchical data set of primitives. This is the JSilver equivalent to ClearSilver's HDF object. This class has no synchronization logic. Follow the same thread-safety semantics as you would for a java.util.ArrayList (i.e. concurrent reads allowed, but ensure you have exclusive access when modifying - should not read whilst another thread writes).


Field Summary
 
Fields inherited from class com.google.clearsilver.jsilver.data.AbstractData
escapeMode
 
Constructor Summary
  NestedMapData()
           
protected NestedMapData(String name, NestedMapData parent, NestedMapData root)
           
 
Method Summary
 void copy(Data from)
          Does a deep copy the attributes and values from one node to another
 void copy(String toPath, Data from)
          Does a deep copy of the attributes and values from one node to another.
 NestedMapData createChild(String path)
          Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist
protected  NestedMapData createChildNode(String chunk)
          Creates a child of this node.
 String getAttribute(String key)
          Returns the value of the node attribute with the given name, or null if there is no value.
 int getAttributeCount()
          Returns the number of attributes on this node.
 Iterable<Map.Entry<String,String>> getAttributes()
          Returns an iterable collection of attribute name/value pairs.
 NestedMapData getChild(String path)
          Retrieves the object that is the root of the subtree at hdfpath, returning null if the subtree doesn't exist
 int getChildCount()
          Returns number of child nodes.
 Iterable<? extends Data> getChildren()
          Returns children of this node.
 String getFullPath()
          Returns the full path to this node via its parent links.
 String getName()
          Returns the name of this HDF node.
 Data getNextSibling()
          Retrieves the node representing the next sibling of this Data node, if any.
 Data getParent()
          Get the parent node.
 Data getRoot()
          Return the root of the tree where the current node lies.
 Data getSymlink()
          Retrieve the symbolic link this node points to.
 String getValue()
          Returns the value of this HDF node, or null if this node has no value.
 boolean hasAttribute(String key)
          Returns true if the node contains an attribute with the given name, false otherwise.
 boolean isFirstSibling()
          Is this the first of its siblings?
 boolean isLastSibling()
          Is this the last of its siblings?
 void optimize()
          Here we optimize the structure for long-term use.
 void removeTree(String path)
          Remove the specified subtree.
 void setAttribute(String key, String value)
          Sets an attribute key and value on the current node, replacing any existing value.
 void setSymlink(Data symLink)
          Set this node to be a symbolic link to another node.
 void setSymlink(String sourcePath, Data destination)
          Set the source node to be a symbolic link to the destination.
 void setSymlink(String sourcePath, String destinationPath)
          Set the source node to be a symbolic link to the destination.
 void setValue(String value)
          Set the value of this node.
 void write(Appendable out, int indent)
          Write out the String representation of this HDF node.
 
Methods inherited from class com.google.clearsilver.jsilver.data.AbstractData
getBooleanValue, getBooleanValue, getEscapeMode, getIntValue, getIntValue, getIntValue, getValue, getValue, setEscapeMode, setValue, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NestedMapData

public NestedMapData()

NestedMapData

protected NestedMapData(String name,
                        NestedMapData parent,
                        NestedMapData root)
Method Detail

createChildNode

protected NestedMapData createChildNode(String chunk)
Creates a child of this node.

Parameters:
chunk - name to give the new child node.
Returns:
the NestedMapData object corresponding to the new node.

getName

public String getName()
Returns the name of this HDF node. The root node has no name, so calling this on the root node will return null.


getFullPath

public String getFullPath()
Returns the full path to this node via its parent links.


getValue

public String getValue()
Returns the value of this HDF node, or null if this node has no value. Every node in the tree can have a value, a child, and a next peer.


setValue

public void setValue(String value)
Set the value of this node. Any symlink that may have been set for this node will be replaced.


setAttribute

public void setAttribute(String key,
                         String value)
Description copied from interface: Data
Sets an attribute key and value on the current node, replacing any existing value.

Parameters:
key - the name of the attribute to add/modify.
value - the value to assign it. Value of null will clear the attribute.

getAttribute

public String getAttribute(String key)
Description copied from interface: Data
Returns the value of the node attribute with the given name, or null if there is no value.


hasAttribute

public boolean hasAttribute(String key)
Description copied from interface: Data
Returns true if the node contains an attribute with the given name, false otherwise.


getAttributeCount

public int getAttributeCount()
Description copied from interface: Data
Returns the number of attributes on this node.


getAttributes

public Iterable<Map.Entry<String,String>> getAttributes()
Description copied from interface: Data
Returns an iterable collection of attribute name/value pairs.

Returns:
an object that can be iterated over to get all the attribute name/value pairs. Should return empty iterator if there are no attributes.

getRoot

public Data getRoot()
Return the root of the tree where the current node lies. If the current node is the root, return this.


getParent

public Data getParent()
Get the parent node.


isFirstSibling

public boolean isFirstSibling()
Is this the first of its siblings?


isLastSibling

public boolean isLastSibling()
Is this the last of its siblings?


getNextSibling

public Data getNextSibling()
Description copied from interface: Data
Retrieves the node representing the next sibling of this Data node, if any.

Returns:
the next sibling Data object or null if this is the last sibling.

getChildCount

public int getChildCount()
Returns number of child nodes.


getChildren

public Iterable<? extends Data> getChildren()
Returns children of this node.


getChild

public NestedMapData getChild(String path)
Retrieves the object that is the root of the subtree at hdfpath, returning null if the subtree doesn't exist


createChild

public NestedMapData createChild(String path)
Retrieves the HDF object that is the root of the subtree at hdfpath, create the subtree if it doesn't exist


removeTree

public void removeTree(String path)
Remove the specified subtree.


setSymlink

public void setSymlink(String sourcePath,
                       String destinationPath)
Set the source node to be a symbolic link to the destination.


setSymlink

public void setSymlink(String sourcePath,
                       Data destination)
Set the source node to be a symbolic link to the destination.


setSymlink

public void setSymlink(Data symLink)
Set this node to be a symbolic link to another node.


getSymlink

public Data getSymlink()
Retrieve the symbolic link this node points to. Will return reference to self if not a symlink.


copy

public void copy(String toPath,
                 Data from)
Description copied from interface: Data
Does a deep copy of the attributes and values from one node to another.

Parameters:
toPath - destination path for the deep copy.
from - Data object that should be copied over.

copy

public void copy(Data from)
Description copied from interface: Data
Does a deep copy the attributes and values from one node to another

Parameters:
from - Data object whose value should be copied over.

write

public void write(Appendable out,
                  int indent)
           throws IOException
Write out the String representation of this HDF node.

Throws:
IOException

optimize

public void optimize()
Here we optimize the structure for long-term use. We call intern() on all Strings to reduce the copies of the same string that appear

Specified by:
optimize in interface Data
Overrides:
optimize in class AbstractData


Copyright © 2010-2012 Google. All Rights Reserved.