@Deprecated @DefaultKey(value="lists") public class ListTool extends Object
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:
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).
Constructor and Description |
---|
ListTool()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
Boolean |
contains(Object list,
Object element)
Deprecated.
Checks if a List/array contains a certain element.
|
Object |
get(Object list,
int index)
Deprecated.
Gets the specified element of a List/array.
|
boolean |
isArray(Object object)
Deprecated.
Checks if an object is an array.
|
Boolean |
isEmpty(Object list)
Deprecated.
Checks if a List/array is empty.
|
boolean |
isList(Object object)
Deprecated.
Checks if an object is a List.
|
Object |
set(Object list,
int index,
Object value)
Deprecated.
Sets the specified element of a List/array.
|
Integer |
size(Object list)
Deprecated.
Gets the size of a List/array.
|
public Object get(Object list, int index)
list
is null.list
is not a List/array.list
doesn't have an index
th value.list
- the List/array object.index
- the index of the List/array to get.public Object set(Object list, int index, Object value)
list
is null.list
is not a List/array.list
doesn't have an index
th value.list
- the List/array object.index
- the index of the List/array to set.value
- the element to set.public Integer size(Object list)
list
is null.list
is not a List/array.list
- the List object.public boolean isArray(Object object)
object
- the object to check.true
if the object is an array.public boolean isList(Object object)
object
- the object to check.true
if the object is a List.public Boolean isEmpty(Object list)
list
- the List/array to check.true
if the List/array is empty.Copyright © 2002–2016 Apache Software Foundation. All rights reserved.