com.google.template.soy.data
Class SoyListData

java.lang.Object
  extended by com.google.template.soy.data.SoyData
      extended by com.google.template.soy.data.restricted.CollectionData
          extended by com.google.template.soy.data.SoyListData
All Implemented Interfaces:
Iterable<SoyData>

public class SoyListData
extends com.google.template.soy.data.restricted.CollectionData
implements Iterable<SoyData>

A list data node in a Soy data tree.


Constructor Summary
SoyListData()
           
SoyListData(Iterable<?> data)
          Constructor that initializes this SoyListData from an existing list.
SoyListData(Object... values)
          Constructor that initializes this SoyListData with the given elements.
 
Method Summary
 void add(boolean value)
          Adds a data value.
 void add(double value)
          Adds a data value.
 void add(int value)
          Adds a data value.
 void add(Object... values)
          Convenience function to add multiple values in one call.
 void add(SoyData value)
          Adds a data value.
 void add(String value)
          Adds a data value.
 List<SoyData> asList()
          Important: Please treat this method as superpackage-private.
 boolean equals(Object other)
          Compares this data object against another for equality in the sense of the operator '==' for Soy expressions.
 SoyData get(int index)
          Gets the data value at a given index.
 boolean getBoolean(int index)
          Precondition: The specified index contains a boolean.
 double getFloat(int index)
          Precondition: The specified index contains a float.
 int getInteger(int index)
          Precondition: The specified index contains an integer.
 SoyListData getListData(int index)
          Precondition: The specified index contains a SoyListData object.
 SoyMapData getMapData(int index)
          Precondition: The specified index contains a SoyMapData object.
 SoyData getSingle(String key)
          Important: Do not use outside of Soy code (treat as superpackage-private).
 String getString(int index)
          Precondition: The specified index contains a string.
 Iterator<SoyData> iterator()
           
 int length()
          Gets the length of this list.
 void putSingle(String key, SoyData value)
          Important: Do not use outside of Soy code (treat as superpackage-private).
 void remove(int index)
          Removes the data value at a given index.
 void removeSingle(String key)
          Important: Do not use outside of Soy code (treat as superpackage-private).
 void set(int index, boolean value)
          Sets a data value at a given index.
 void set(int index, double value)
          Sets a data value at a given index.
 void set(int index, int value)
          Sets a data value at a given index.
 void set(int index, SoyData value)
          Sets a data value at a given index.
 void set(int index, String value)
          Sets a data value at a given index.
 boolean toBoolean()
          Converts this data object into a boolean (e.g.
 String toString()
          Converts this data object into a string (e.g.
 
Methods inherited from class com.google.template.soy.data.restricted.CollectionData
ensureValidValue, get, getBoolean, getFloat, getInteger, getListData, getMapData, getString, put, put, put, put, put, put, remove
 
Methods inherited from class com.google.template.soy.data.SoyData
booleanValue, createFromExistingData, createFromExistingData, floatValue, integerValue, numberValue, stringValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SoyListData

public SoyListData()

SoyListData

public SoyListData(Iterable<?> data)
Constructor that initializes this SoyListData from an existing list.

Parameters:
data - The initial data in an existing Iterable.

SoyListData

public SoyListData(Object... values)
Constructor that initializes this SoyListData with the given elements.

Parameters:
values - The initial data to add.
Method Detail

asList

public List<SoyData> asList()
Important: Please treat this method as superpackage-private. Do not call this method from outside the 'tofu' and 'data' packages. Returns a view of this SoyListData object as a List.


toString

public String toString()
Converts this data object into a string (e.g. when used in a string context).

This method should only be used for debugging purposes.

Specified by:
toString in class SoyData
Returns:
The value of this data object if coerced into a string.

toBoolean

public boolean toBoolean()
Converts this data object into a boolean (e.g. when used in a boolean context). In other words, this method tells whether this object is truthy.

A list is always truthy.

Specified by:
toBoolean in class SoyData
Returns:
The value of this data object if coerced into a boolean. I.e. true if this object is truthy, false if this object is falsy.

equals

public boolean equals(Object other)
Description copied from class: SoyData
Compares this data object against another for equality in the sense of the operator '==' for Soy expressions.

Specified by:
equals in class SoyData
Parameters:
other - The other data object to compare against.
Returns:
True if the two objects are equal.

length

public int length()
Gets the length of this list.

Returns:
The length of this list.

iterator

public Iterator<SoyData> iterator()
Specified by:
iterator in interface Iterable<SoyData>

add

public void add(Object... values)
Convenience function to add multiple values in one call.

Parameters:
values - The data to add.

add

public void add(SoyData value)
Adds a data value.

Parameters:
value - The data to add.

add

public void add(boolean value)
Adds a data value.

Parameters:
value - The data to add.

add

public void add(int value)
Adds a data value.

Parameters:
value - The data to add.

add

public void add(double value)
Adds a data value.

Parameters:
value - The data to add.

add

public void add(String value)
Adds a data value.

Parameters:
value - The data to add.

set

public void set(int index,
                SoyData value)
Sets a data value at a given index.

Parameters:
index - The index.
value - The data to set.

set

public void set(int index,
                boolean value)
Sets a data value at a given index.

Parameters:
index - The index.
value - The data to set.

set

public void set(int index,
                int value)
Sets a data value at a given index.

Parameters:
index - The index.
value - The data to set.

set

public void set(int index,
                double value)
Sets a data value at a given index.

Parameters:
index - The index.
value - The data to set.

set

public void set(int index,
                String value)
Sets a data value at a given index.

Parameters:
index - The index.
value - The data to set.

remove

public void remove(int index)
Removes the data value at a given index.

Parameters:
index - The index.

get

public SoyData get(int index)
Gets the data value at a given index.

Parameters:
index - The index.
Returns:
The data at the given index, or null of the index is undefined.

getMapData

public SoyMapData getMapData(int index)
Precondition: The specified index contains a SoyMapData object. Gets the SoyMapData at the given index.

Parameters:
index - The index.
Returns:
The SoyMapData at the given index, or null of the index is undefined.

getListData

public SoyListData getListData(int index)
Precondition: The specified index contains a SoyListData object. Gets the SoyListData at the given index.

Parameters:
index - The index.
Returns:
The SoyListData at the given index, or null of the index is undefined.

getBoolean

public boolean getBoolean(int index)
Precondition: The specified index contains a boolean. Gets the boolean at the given index.

Parameters:
index - The index.
Returns:
The boolean at the given index, or null of the index is undefined.

getInteger

public int getInteger(int index)
Precondition: The specified index contains an integer. Gets the integer at the given index.

Parameters:
index - The index.
Returns:
The integer at the given index, or null of the index is undefined.

getFloat

public double getFloat(int index)
Precondition: The specified index contains a float. Gets the float at the given index.

Parameters:
index - The index.
Returns:
The float at the given index, or null of the index is undefined.

getString

public String getString(int index)
Precondition: The specified index contains a string. Gets the string at the given index.

Parameters:
index - The index.
Returns:
The string at the given index, or null of the index is undefined.

putSingle

public 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.

Specified by:
putSingle in class com.google.template.soy.data.restricted.CollectionData
Parameters:
key - An individual key.
value - The data to put at the specified key.

removeSingle

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

Specified by:
removeSingle in class com.google.template.soy.data.restricted.CollectionData
Parameters:
key - An individual key.

getSingle

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

Specified by:
getSingle in class com.google.template.soy.data.restricted.CollectionData
Parameters:
key - An individual key.
Returns:
The data at the specified key, or null if the key is not defined.