| java.lang.Object org.mortbay.util.LazyList
LazyList | public class LazyList implements Cloneable,Serializable(Code) | | Lazy List creation.
A List helper class that attempts to avoid unneccessary List
creation. If a method needs to create a List to return, but it is
expected that this will either be empty or frequently contain a
single item, then using LazyList will avoid additional object
creations by using Collections.EMPTY_LIST or
Collections.singletonList where possible.
Usage
Object lazylist =null;
while(loopCondition)
{
Object item = getItem();
if (item.isToBeAdded())
lazylist = LazyList.add(lazylist,item);
}
return LazyList.getList(lazylist);
An ArrayList of default size is used as the initial LazyList.
See Also: java.util.List author: Greg Wilkins (gregw) |
Method Summary | |
public static Object | add(Object list, Object item) Add an item to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: item - The item to add. | public static Object | add(Object list, int index, Object item) Add an item to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: index - The index to add the item at. Parameters: item - The item to add. | public static Object | addArray(Object list, Object[] array) Add the contents of an array to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: collection - The Collection whose contents should be added. | public static Object | addCollection(Object list, Collection collection) Add the contents of a Collection to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: collection - The Collection whose contents should be added. | public static Object[] | addToArray(Object[] array, Object item, Class type) | public static List | array2List(Object[] array) | public static Object | clone(Object list) | public static boolean | contains(Object list, Object item) | public static Object | ensureSize(Object list, int initialSize) Ensure the capcity of the underlying list. | public static Object | get(Object list, int i) | public static List | getList(Object list) Get the real List from a LazyList. | public static List | getList(Object list, boolean nullForEmpty) Get the real List from a LazyList.
Parameters: list - A LazyList returned from LazyList.add(Object) or null Parameters: nullForEmpty - If true, null is returned instead of anempty list. | public static Iterator | iterator(Object list) | public static ListIterator | listIterator(Object list) | public static Object | remove(Object list, Object o) | public static Object | remove(Object list, int i) | public static Object[] | removeFromArray(Object[] array, Object item) | public static int | size(Object list) | public static Object | toArray(Object list, Class aClass) | public static String | toString(Object list) | public static String[] | toStringArray(Object list) |
add | public static Object add(Object list, Object item)(Code) | | Add an item to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: item - The item to add. The lazylist created or added to. |
add | public static Object add(Object list, int index, Object item)(Code) | | Add an item to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: index - The index to add the item at. Parameters: item - The item to add. The lazylist created or added to. |
addArray | public static Object addArray(Object list, Object[] array)(Code) | | Add the contents of an array to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: collection - The Collection whose contents should be added. The lazylist created or added to. |
addCollection | public static Object addCollection(Object list, Collection collection)(Code) | | Add the contents of a Collection to a LazyList
Parameters: list - The list to add to or null if none yet created. Parameters: collection - The Collection whose contents should be added. The lazylist created or added to. |
addToArray | public static Object[] addToArray(Object[] array, Object item, Class type)(Code) | | Add element to an array
Parameters: array - The array to add to (or null) Parameters: item - The item to add Parameters: type - The type of the array (in case of null array) new array with contents of array plus item |
array2List | public static List array2List(Object[] array)(Code) | | Parameters: array - Any array of object A new modifiable list initialised with the elements from array . |
ensureSize | public static Object ensureSize(Object list, int initialSize)(Code) | | Ensure the capcity of the underlying list.
|
get | public static Object get(Object list, int i)(Code) | | Get item from the list
Parameters: list - A LazyList returned from LazyList.add(Object) or null Parameters: i - int index the item from the list. |
getList | public static List getList(Object list)(Code) | | Get the real List from a LazyList.
Parameters: list - A LazyList returned from LazyList.add(Object) The List of added items, which may be an EMPTY_LISTor a SingletonList. |
getList | public static List getList(Object list, boolean nullForEmpty)(Code) | | Get the real List from a LazyList.
Parameters: list - A LazyList returned from LazyList.add(Object) or null Parameters: nullForEmpty - If true, null is returned instead of anempty list. The List of added items, which may be null, an EMPTY_LISTor a SingletonList. |
size | public static int size(Object list)(Code) | | The size of a lazy List
Parameters: list - A LazyList returned from LazyList.add(Object) or null the size of the list. |
|
|