|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.velocity.tools.generic.ArrayTool
Tool for working with arrays in Velocity templates. It provides a method to get and set specified elements, retrieve the length, and create clones of an array object. Also provides a method to convert arrays into java.util.List's.
Example uses:
$primes -> new int[] {2, 3, 5, 7}
$array.length($primes) -> 4
$array.get($primes, 2) -> 5
$array.clone($primes) -> int[] {2, 3, 5, 7}, != $primes
$array.set($primes, 2, 1) -> (primes[2] becomes 1)
$array.get($primes, 2) -> 1
$array.get($clone, 2) -> 5
Example toolbox.xml config (if you want to use this with VelocityView):
<tool>
<key>array</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ArrayTool</class>
</tool>
This tool is entirely threadsafe, and has no instance members. It may be used in any scope (request, session, or application).
| Constructor Summary | |
ArrayTool()
Default constructor. |
|
| Method Summary | |
java.lang.Object |
clone(java.lang.Object array)
Gets the clone of an array. |
java.lang.Object |
get(java.lang.Object array,
int index)
Gets the specified element of an array. |
boolean |
isArray(java.lang.Object object)
Checks if an object is an array. |
java.lang.Integer |
length(java.lang.Object array)
Gets the length of an array. |
java.util.List |
list(java.lang.Object array)
Converts an array object into a java.util.List. |
java.lang.Object |
set(java.lang.Object array,
int index,
java.lang.Object value)
Sets the specified element of an array. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ArrayTool()
| Method Detail |
public java.util.List list(java.lang.Object array)
array - an array object.
public java.lang.Object get(java.lang.Object array,
int index)
array is null.array is not an array.array doesn't have an indexth value.
array - the array object.index - the index of the array to get.
public java.lang.Object set(java.lang.Object array,
int index,
java.lang.Object value)
array is null.array is not an array.array doesn't have an indexth value.
array - the array object.index - the index of the array to set.value - the element to set.public java.lang.Integer length(java.lang.Object array)
array is null.array is not an array.
array - the array object.
public java.lang.Object clone(java.lang.Object array)
array is null.array is not an array.
array - the array object.
public boolean isArray(java.lang.Object object)
object - the object to check.
true if the object is an array.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||