org.webmacro.servlet
Class ListUtil

java.lang.Object
  |
  +--org.webmacro.servlet.ListUtil

public class ListUtil
extends java.lang.Object

A utility class for templates loaded into the context as "List" by ListTool. It allows template designers to work with Java arrays and lists using without having to distinguish between them.

Since:
Oct. 2000
Version:
$Revision: 1.7 $
Author:
Keats Kirsch, Zeljko Trogrlic
See Also:
ListTool

Method Summary
static java.util.List append(java.lang.Object o1, java.lang.Object o2)
          append one list to the end of another and return the expanded list.
static boolean contains(java.util.List list, java.lang.Object o)
           
static boolean contains(java.lang.Object[] oa, java.lang.Object o)
           
static boolean contains(java.lang.Object arr, java.lang.Object o)
           
static java.util.List copy(java.lang.Object o)
          create a new list (ArrayList) with all the elements in the supplied list
static java.util.ArrayList create()
          create a new ArrayList
static java.util.ArrayList create(int capacity)
          create a new ArrayList with the specified capacity
static java.util.List createRange(int rangeBegin, int rangeEnd)
           
static java.util.List createRange(int rangeBegin, int rangeEnd, int incr)
           
static ListUtil getInstance()
           
static java.lang.Object getItem(java.util.List list, int pos)
          Allows access to elements in a List by position.
static java.lang.Object getItem(java.lang.Object[] oa, int pos)
          Allows access to elements in an array by position.
static java.lang.Object getItem(java.lang.Object arr, int pos)
          Allows access to elements in a array of primitives by position.
 boolean isArray(java.lang.Object o)
           
static boolean isEmpty(java.lang.Object arg)
           
 boolean isList(java.lang.Object o)
           
static void main(java.lang.String[] args)
          test harness
static int size(java.util.List list)
           
static int size(java.lang.Object arr)
           
static int size(java.lang.Object[] oa)
           
static java.util.List split(java.util.List arg, int colCount)
          Splits list into multiple lists of equal size.
static java.util.List split(java.util.List arg, int colCount, boolean pad)
          Splits list into multiple lists of equal size.
static java.util.List split(java.util.List arg, int colCount, boolean pad, java.lang.Object padValue)
          Splits list into multiple lists of equal size.
static java.util.List split(java.util.List arg, int colCount, java.lang.Object padValue)
          Splits list into multiple lists of equal size.
static java.lang.Object[] split(java.lang.Object[] arg, int colCount)
          Splits array into multiple arrays of equal size.
static java.lang.Object[] split(java.lang.Object[] arg, int colCount, boolean pad)
          Splits array into multiple arrays of equal size.
static java.lang.Object[][] split(java.lang.Object[] arg, int colCount, boolean pad, java.lang.Object padValue)
          Splits array into multiple arrays of equal size.
static java.lang.Object[] split(java.lang.Object[] arg, int colCount, java.lang.Object padValue)
          Splits array into multiple arrays of equal size.
static java.util.List toList(java.lang.Object arg)
          Returns a List for any Object.
static java.util.List transposeSplit(java.util.List arg, int colCount)
          Transposes and splits list into multiple lists of equal size.
static java.util.List transposeSplit(java.util.List arg, int colCount, boolean pad)
          Transposes and splits list into multiple lists of equal size.
static java.util.List transposeSplit(java.util.List arg, int colCount, boolean pad, java.lang.Object padValue)
          Transposes and splits list into multiple lists of equal size.
static java.util.List transposeSplit(java.util.List arg, int colCount, java.lang.Object padValue)
          Transposes and splits list into multiple lists of equal size.
static java.lang.Object[][] transposeSplit(java.lang.Object[] arg, int colCount)
          Transposes and splits array into multiple arrays of equal size.
static java.lang.Object[][] transposeSplit(java.lang.Object[] arg, int colCount, boolean pad)
          Transposes and splits array into multiple arrays of equal size.
static java.lang.Object[][] transposeSplit(java.lang.Object[] arg, int colCount, boolean pad, java.lang.Object padValue)
          Transposes and splits array into multiple arrays of equal size.
static java.lang.Object[][] transposeSplit(java.lang.Object[] arg, int colCount, java.lang.Object padValue)
          Transposes and splits array into multiple arrays of equal size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ListUtil getInstance()
Returns:
the singleton instance of this class

isList

public boolean isList(java.lang.Object o)
Parameters:
o -  
Returns:
true if the argument implements the java.util.List interface, false otherwise.

isArray

public boolean isArray(java.lang.Object o)
Parameters:
o -  
Returns:
true if the argument is an array, otherwise false.

isEmpty

public static boolean isEmpty(java.lang.Object arg)
Parameters:
arg -  
Returns:
false if the argument is a list or an array with at least one element, true otherwise.

toList

public static java.util.List toList(java.lang.Object arg)
Returns a List for any Object. The action taken depends on the type of the argument:
Parameters:
arg -  

getItem

public static java.lang.Object getItem(java.lang.Object[] oa,
                                       int pos)
Allows access to elements in an array by position. Index is zero based.
Parameters:
oa -  
pos -  

getItem

public static java.lang.Object getItem(java.util.List list,
                                       int pos)
Allows access to elements in a List by position. Index is zero based.
Parameters:
list -  
pos -  

getItem

public static java.lang.Object getItem(java.lang.Object arr,
                                       int pos)
Allows access to elements in a array of primitives by position. The index is zero based.
Parameters:
arr - the array of primitives
pos - the position (0 based) to retrieve from

size

public static int size(java.lang.Object[] oa)
Parameters:
oa -  
Returns:
number of elements in array argument

size

public static int size(java.util.List list)
Parameters:
list -  
Returns:
number of elements in List argument

size

public static int size(java.lang.Object arr)

contains

public static boolean contains(java.util.List list,
                               java.lang.Object o)
Parameters:
list -  
o -  
Returns:
true if List argument contains the object argument, else false

contains

public static boolean contains(java.lang.Object[] oa,
                               java.lang.Object o)
Parameters:
oa -  
o -  
Returns:
true if Array argument contains the object argument, else false

contains

public static boolean contains(java.lang.Object arr,
                               java.lang.Object o)
Parameters:
arr -  
o -  
Returns:
true if array argument contains the object argument, else false

split

public static java.util.List split(java.util.List arg,
                                   int colCount)
Splits list into multiple lists of equal size. If list size cannot be divided by column count, last part is padded with nulls.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
Returns:
List of list parts.

split

public static java.util.List split(java.util.List arg,
                                   int colCount,
                                   boolean pad)
Splits list into multiple lists of equal size. If list size cannot be divided by column count, fill parameter determines should it be padded with nulls or not.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
Returns:
List of list parts.

split

public static java.util.List split(java.util.List arg,
                                   int colCount,
                                   java.lang.Object padValue)
Splits list into multiple lists of equal size. If list size cannot be divided by column count, it's padded with pad value.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
padValue - Value that will be used for padding.
Returns:
List of list parts.

split

public static java.util.List split(java.util.List arg,
                                   int colCount,
                                   boolean pad,
                                   java.lang.Object padValue)
Splits list into multiple lists of equal size. If list size cannot be divided by column count, fill parameter determines should it be padded with pad value or not.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
padValue - Value that will be used for padding.
Returns:
List of list parts.

split

public static java.lang.Object[] split(java.lang.Object[] arg,
                                       int colCount)
Splits array into multiple arrays of equal size. If list size cannot be divided by column count, last part is padded with nulls.
Parameters:
arg - array to be splitted.
colCount - Number of elements in each split.
Returns:
array of list parts.

split

public static java.lang.Object[] split(java.lang.Object[] arg,
                                       int colCount,
                                       boolean pad)
Splits array into multiple arrays of equal size. If list size cannot be divided by column count, fill parameter determines should it be padded with nulls or not.
Parameters:
arg - array to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
Returns:
array of list parts.

split

public static java.lang.Object[] split(java.lang.Object[] arg,
                                       int colCount,
                                       java.lang.Object padValue)
Splits array into multiple arrays of equal size. If list size cannot be divided by column count, it's padded with pad value.
Parameters:
arg - Object[] to be splitted.
colCount - Number of elements in each split.
padValue - Value that will be used for padding.
Returns:
Object[] of list parts.

split

public static java.lang.Object[][] split(java.lang.Object[] arg,
                                         int colCount,
                                         boolean pad,
                                         java.lang.Object padValue)
Splits array into multiple arrays of equal size. If array size cannot be divided by column count, fill parameter determines should it be padded with nulls or not.
Parameters:
arg - Array to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
padValue - Value that will be used for padding.
Returns:
Array of array parts.

transposeSplit

public static java.lang.Object[][] transposeSplit(java.lang.Object[] arg,
                                                  int colCount)
Transposes and splits array into multiple arrays of equal size. If array size cannot be divided by column count, it's padded with nulls.
Parameters:
arg - Array to be splitted.
colCount - Number of elements in each split.
Returns:
Array of array parts.

transposeSplit

public static java.lang.Object[][] transposeSplit(java.lang.Object[] arg,
                                                  int colCount,
                                                  boolean pad)
Transposes and splits array into multiple arrays of equal size. If array size cannot be divided by column count, fill parameter determines should it be padded with nulls or not.
Parameters:
arg - Array to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
Returns:
Array of array parts.

transposeSplit

public static java.lang.Object[][] transposeSplit(java.lang.Object[] arg,
                                                  int colCount,
                                                  java.lang.Object padValue)
Transposes and splits array into multiple arrays of equal size. If array size cannot be divided by column count, it's padded with padValue.
Parameters:
arg - Array to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
padValue - Value that will be used for padding.
Returns:
Array of array parts.

transposeSplit

public static java.lang.Object[][] transposeSplit(java.lang.Object[] arg,
                                                  int colCount,
                                                  boolean pad,
                                                  java.lang.Object padValue)
Transposes and splits array into multiple arrays of equal size. If array size cannot be divided by column count, fill parameter determines should it be padded with padValue or not.
Parameters:
arg - Array to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
padValue - Value that will be used for padding.
Returns:
Array of array parts.

transposeSplit

public static java.util.List transposeSplit(java.util.List arg,
                                            int colCount)
Transposes and splits list into multiple lists of equal size. If list size cannot be divided by column count, it's padded with nulls.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
Returns:
List of list parts.

transposeSplit

public static java.util.List transposeSplit(java.util.List arg,
                                            int colCount,
                                            boolean pad)
Transposes and splits list into multiple lists of equal size. If list size cannot be divided by column count, fill parameter determines should it be padded with nulls or not.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
Returns:
List of list parts.

transposeSplit

public static java.util.List transposeSplit(java.util.List arg,
                                            int colCount,
                                            java.lang.Object padValue)
Transposes and splits list into multiple lists of equal size. If list size cannot be divided by column count, it's padded with padValue.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
padValue - Value that will be used for padding.
Returns:
List of list parts.

transposeSplit

public static java.util.List transposeSplit(java.util.List arg,
                                            int colCount,
                                            boolean pad,
                                            java.lang.Object padValue)
Transposes and splits list into multiple lists of equal size. If list size cannot be divided by column count, fill parameter determines should it be padded with padValue or not.
Parameters:
arg - List to be splitted.
colCount - Number of elements in each split.
pad - Last split should be null padded?
padValue - Value that will be used for padding.
Returns:
List of list parts.

createRange

public static java.util.List createRange(int rangeBegin,
                                         int rangeEnd)

createRange

public static java.util.List createRange(int rangeBegin,
                                         int rangeEnd,
                                         int incr)

create

public static java.util.ArrayList create()
create a new ArrayList

create

public static java.util.ArrayList create(int capacity)
create a new ArrayList with the specified capacity

append

public static java.util.List append(java.lang.Object o1,
                                    java.lang.Object o2)
append one list to the end of another and return the expanded list. If the first list is not expandable, return a new expandable list with the elements of each list appended

copy

public static java.util.List copy(java.lang.Object o)
create a new list (ArrayList) with all the elements in the supplied list

main

public static void main(java.lang.String[] args)
test harness