com.google.template.soy.data.restricted
Class CollectionData

java.lang.Object
  extended by com.google.template.soy.data.SoyData
      extended by com.google.template.soy.data.restricted.CollectionData
Direct Known Subclasses:
SoyListData, SoyMapData

public abstract class CollectionData
extends SoyData

Abstract superclass for a node in a Soy data tree that represents a collection of data (i.e. an internal node).

Important: This class may only be used in implementing plugins (e.g. functions, directives).


Constructor Summary
CollectionData()
           
 
Method Summary
protected static SoyData ensureValidValue(SoyData value)
          Ensures that the given value is valid for insertion into a Soy data tree.
 SoyData get(String keyStr)
          Gets the data at the specified key string.
 boolean getBoolean(String keyStr)
          Precondition: The specified key string is the path to a boolean.
 double getFloat(String keyStr)
          Precondition: The specified key string is the path to a float.
 int getInteger(String keyStr)
          Precondition: The specified key string is the path to an integer.
 SoyListData getListData(String keyStr)
          Precondition: The specified key string is the path to a SoyListData object.
 SoyMapData getMapData(String keyStr)
          Precondition: The specified key string is the path to a SoyMapData object.
abstract  SoyData getSingle(String key)
          Important: Do not use outside of Soy code (treat as superpackage-private).
 String getString(String keyStr)
          Precondition: The specified key string is the path to a string.
 void put(Object... data)
          Convenience function to put multiple mappings in one call.
 void put(String keyStr, boolean value)
          Puts data into this data tree at the specified key string.
 void put(String keyStr, double value)
          Puts data into this data tree at the specified key string.
 void put(String keyStr, int value)
          Puts data into this data tree at the specified key string.
 void put(String keyStr, SoyData value)
          Puts data into this data tree at the specified key string.
 void put(String keyStr, String value)
          Puts data into this data tree at the specified key string.
abstract  void putSingle(String key, SoyData value)
          Important: Do not use outside of Soy code (treat as superpackage-private).
 void remove(String keyStr)
          Removes the data at the specified key string.
abstract  void removeSingle(String key)
          Important: Do not use outside of Soy code (treat as superpackage-private).
 
Methods inherited from class com.google.template.soy.data.SoyData
booleanValue, createFromExistingData, createFromExistingData, equals, floatValue, integerValue, numberValue, stringValue, toBoolean, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CollectionData

public CollectionData()
Method Detail

put

public void put(Object... data)
Convenience function to put multiple mappings in one call.

Parameters:
data - The mappings to put, as alternating keys/values. Indices 0, 2, 4, ... must be valid key strings. Indices 1, 3, 5, ... must be valid Soy data values.
Throws:
SoyDataException - When attempting to add an invalid varargs list or a mapping containing an invalid key.

put

public void put(String keyStr,
                SoyData value)
Puts data into this data tree at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
value - The data to put at the specified location.

put

public void put(String keyStr,
                boolean value)
Puts data into this data tree at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
value - The data to put at the specified location.

put

public void put(String keyStr,
                int value)
Puts data into this data tree at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
value - The data to put at the specified location.

put

public void put(String keyStr,
                double value)
Puts data into this data tree at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
value - The data to put at the specified location.

put

public void put(String keyStr,
                String value)
Puts data into this data tree at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
value - The data to put at the specified location.

remove

public void remove(String keyStr)
Removes the data at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.

get

public SoyData get(String keyStr)
Gets the data at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
Returns:
The data at the specified key string, or null if there's no data at the location.

getMapData

public SoyMapData getMapData(String keyStr)
Precondition: The specified key string is the path to a SoyMapData object. Gets the SoyMapData at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
Returns:
The SoyMapData at the specified key string, or null if no data is stored there.

getListData

public SoyListData getListData(String keyStr)
Precondition: The specified key string is the path to a SoyListData object. Gets the SoyListData at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
Returns:
The SoyListData at the specified key string, or null if no data is stored there.

getBoolean

public boolean getBoolean(String keyStr)
Precondition: The specified key string is the path to a boolean. Gets the boolean at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
Returns:
The boolean at the specified key string.
Throws:
IllegalArgumentException - If no data is stored at the specified key.

getInteger

public int getInteger(String keyStr)
Precondition: The specified key string is the path to an integer. Gets the integer at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
Returns:
The integer at the specified key string.
Throws:
IllegalArgumentException - If no data is stored at the specified key.

getFloat

public double getFloat(String keyStr)
Precondition: The specified key string is the path to a float. Gets the float at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
Returns:
The float at the specified key string.
Throws:
IllegalArgumentException - If no data is stored at the specified key.

getString

public String getString(String keyStr)
Precondition: The specified key string is the path to a string. Gets the string at the specified key string.

Parameters:
keyStr - One or more map keys and/or list indices (separated by '.' if multiple parts). Indicates the path to the location within this data tree.
Returns:
The string at the specified key string.
Throws:
IllegalArgumentException - If no data is stored at the specified key.

putSingle

public abstract void putSingle(String key,
                               SoyData value)
Important: Do not use outside of Soy code (treat as superpackage-private). Puts data into this data object at the specified key.

Parameters:
key - An individual key.
value - The data to put at the specified key.

removeSingle

public abstract void removeSingle(String key)
Important: Do not use outside of Soy code (treat as superpackage-private). Removes the data at the specified key.

Parameters:
key - An individual key.

getSingle

public abstract SoyData getSingle(String key)
Important: Do not use outside of Soy code (treat as superpackage-private). Gets the data at the specified key.

Parameters:
key - An individual key.
Returns:
The data at the specified key, or null if the key is not defined.

ensureValidValue

protected static SoyData ensureValidValue(SoyData value)
Ensures that the given value is valid for insertion into a Soy data tree. If the value is not null, then simply returns it, else return NullData.

Parameters:
value - The value to ensure validity for.
Returns:
The given value if it's not null, or NullData if it is null.