Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.velocity.tools.generic
Class ExtendedListTool

    java.lang.Object
      org.apache.velocity.tools.generic.ListTool
          org.apache.velocity.tools.generic.ExtendedListTool

public class ExtendedListTool
extends ListTool

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

Version:
  $Id: ExtendedListTool.java,v 1.1 2006/03/23 06:36:11 czarneckid Exp $
Author:
  Shinobu Kawai

Constructor Summary
`ExtendedListTool()` Default constructor.

Method Summary
`java.lang.Object` | `clone(java.lang.Object list)` Gets the clone of a List/array.
`java.lang.Integer` | `length(java.lang.Object array)` Gets the length of an array/List.
`java.lang.Object` | `toArray(java.lang.Object list)` Converts a List object into an array.
`java.util.List` | `toList(java.lang.Object array)` Converts an array object into a List.

Methods inherited from class org.apache.velocity.tools.generic.ListTool
`contains, get, isArray, isEmpty, isList, set, size`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ExtendedListTool

    public ExtendedListTool()

  Default constructor.

Method Detail

### toList

    public java.util.List toList(java.lang.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.
  Returns:
    the converted java.util.List.

### toArray

    public java.lang.Object toArray(java.lang.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.
  Returns:
    the converted array.

### length

    public java.lang.Integer length(java.lang.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 `ListTool.size(Object)` method.

  Parameters:
    `array` - the array object.
  Returns:
    the length of the array.
  See Also:
    `ListTool.size(Object)`

### clone

    public java.lang.Object clone(java.lang.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.
  Returns:
    the clone of the List/array.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD