| java.lang.Object org.apache.velocity.tools.generic.ListTool org.apache.velocity.tools.generic.ExtendedListTool
ExtendedListTool | public class ExtendedListTool extends ListTool (Code) | | Tool for working with Lists and arrays in Velocity templates.
In addition to the features ListTool provides,
it provides the function to retrieve the length,
and create clones of a list or an array object.
Also provides a method to convert arrays into Lists and
Lists into arrays.
Example uses:
$primes -> new int[] {2, 3, 5, 7}
$list.length($primes) -> 4
$list.get($primes, 2) -> 5
$list.clone($primes) -> int[] {2, 3, 5, 7}, != $primes
$list.set($primes, 2, 1) -> (primes[2] becomes 1)
$list.get($primes, 2) -> 1
$list.get($clone, 2) -> 5
Example toolbox.xml config (if you want to use this with VelocityView):
<tool>
<key>list</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ExtendedListTool</class>
</tool>
This tool is entirely threadsafe, and has no instance members.
It may be used in any scope (request, session, or application).
author: Shinobu Kawai version: $Id: ExtendedListTool.java,v 1.1 2006/03/23 06:36:11 czarneckid Exp $ |
Method Summary | |
public Object | clone(Object list) Gets the clone of a List/array.
It will return null under the following conditions:
list is null.
list is not a List/array.
Parameters: list - the List/array object. | public Integer | length(Object array) Gets the length of an array/List.
It will return null under the following conditions:
array is null.
array is not an array/List.
The result will be same as the
ExtendedListTool.size(Object) method.
Parameters: array - the array object. | public Object | toArray(Object list) Converts a List object into an array.
-
If the object is already an array,
it will return the object itself.
-
If the object is a List,
it will return an array according to the object's
toArray() method.
-
If the object is none of the above, it will return null.
Parameters: list - a List object. | public List | toList(Object array) Converts an array object into a List.
-
If the object is already a List,
it will return the object itself.
-
If the object is an array of an Object,
it will return a List of the elements.
-
If the object is an array of a primitive type,
it will return a List of the elements wrapped in their wrapper class.
-
If the object is none of the above, it will return null.
Parameters: array - an array object. |
ExtendedListTool | public ExtendedListTool()(Code) | | Default constructor.
|
clone | public Object clone(Object list)(Code) | | Gets the clone of a List/array.
It will return null under the following conditions:
list is null.
list is not a List/array.
Parameters: list - the List/array object. the clone of the List/array. |
toArray | public Object toArray(Object list)(Code) | | Converts a List object into an array.
-
If the object is already an array,
it will return the object itself.
-
If the object is a List,
it will return an array according to the object's
toArray() method.
-
If the object is none of the above, it will return null.
Parameters: list - a List object. the converted array. |
toList | public List toList(Object array)(Code) | | Converts an array object into a List.
-
If the object is already a List,
it will return the object itself.
-
If the object is an array of an Object,
it will return a List of the elements.
-
If the object is an array of a primitive type,
it will return a List of the elements wrapped in their wrapper class.
-
If the object is none of the above, it will return null.
Parameters: array - an array object. the converted java.util.List. |
|
|