Class ListTool
- java.lang.Object
-
- org.apache.velocity.tools.generic.ListTool
-
@Deprecated @DefaultKey("lists") public class ListTool extends Object
Deprecated.Tool for working with Lists and arrays in Velocity templates.With the release of Velocity 1.6, this class is largely obsolete since Velocity 1.6 now allows all List methods to be called on arrays within templates.
It provides a method to get and set specified elements. Also provides methods to perform the following actions to Lists and arrays:
- Check if it is empty.
- Check if it contains a certain element.
Example uses: $primes -> new int[] {2, 3, 5, 7} $lists.size($primes) -> 4 $lists.get($primes, 2) -> 5 $lists.set($primes, 2, 1) -> (primes[2] becomes 1) $lists.get($primes, 2) -> 1 $lists.isEmpty($primes) -> false $lists.contains($primes, 7) -> true Example tools.xml config (if you want to use this with VelocityView): <tools> <toolbox scope="application"> <tool class="org.apache.velocity.tools.generic.ListTool"/> </toolbox> </tools>This tool is entirely threadsafe, and has no instance members. It may be used in any scope (request, session, or application).
- Since:
- VelocityTools 1.2
- Version:
- $Id: $
- Author:
- Shinobu Kawai
-
-
Constructor Summary
Constructors Constructor Description ListTool()Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Booleancontains(Object list, Object element)Deprecated.Checks if a List/array contains a certain element.Objectget(Object list, int index)Deprecated.Gets the specified element of a List/array.booleanisArray(Object object)Deprecated.Checks if an object is an array.BooleanisEmpty(Object list)Deprecated.Checks if a List/array is empty.booleanisList(Object object)Deprecated.Checks if an object is a List.Objectset(Object list, int index, Object value)Deprecated.Sets the specified element of a List/array.Integersize(Object list)Deprecated.Gets the size of a List/array.
-
-
-
Method Detail
-
get
public Object get(Object list, int index)
Deprecated.Gets the specified element of a List/array. It will return null under the following conditions:listis null.listis not a List/array.listdoesn't have anindexth value.
- Parameters:
list- the List/array object.index- the index of the List/array to get.- Returns:
- the specified element of the List/array.
-
set
public Object set(Object list, int index, Object value)
Deprecated.Sets the specified element of a List/array. It will return null under the following conditions:listis null.listis not a List/array.listdoesn't have anindexth value.
- Parameters:
list- the List/array object.index- the index of the List/array to set.value- the element to set.- Returns:
- blank if set, null if not set.
-
size
public Integer size(Object list)
Deprecated.Gets the size of a List/array. It will return null under the following conditions:listis null.listis not a List/array.
- Parameters:
list- the List object.- Returns:
- the size of the List.
-
isArray
public boolean isArray(Object object)
Deprecated.Checks if an object is an array.- Parameters:
object- the object to check.- Returns:
trueif the object is an array.
-
isList
public boolean isList(Object object)
Deprecated.Checks if an object is a List.- Parameters:
object- the object to check.- Returns:
trueif the object is a List.
-
isEmpty
public Boolean isEmpty(Object list)
Deprecated.Checks if a List/array is empty.- Parameters:
list- the List/array to check.- Returns:
trueif the List/array is empty.
-
-