org.mortbay.util
Class LazyList
java.lang.Object
org.mortbay.util.LazyList
public class LazyList
extends java.lang.Object
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.
protected Object | add(Object list, Collection collection) - Use addCollection
|
static Object | add(Object list, Object item) - Add an item to a LazyList
|
static Object | add(Object list, int index, Object item) - Add an item to a LazyList
|
static Object | addCollection(Object list, Collection collection) - Add the contents of a Collection to a LazyList
|
static Object | clone(Object list)
|
static boolean | contains(Object list, Object item)
|
static Object | ensureSize(Object list, int initialSize)
|
static Object | get(Object list, int i) - Get item from the list
|
static List | getList(Object list) - Get the real List from a LazyList.
|
static List | getList(Object list, boolean nullForEmpty) - Get the real List from a LazyList.
|
static Iterator | iterator(Object list)
|
static ListIterator | listIterator(Object list)
|
static Object | remove(Object list, Object o)
|
static Object | remove(Object list, int i)
|
static int | size(Object list) - The size of a lazy List
|
static String | toString(Object list)
|
static String[] | toStringArray(Object list)
|
add
protected Object add(Object list,
Collection collection)
Use addCollection
Add the contents of a Collection to a LazyList
list
- The list to add to or null if none yet created.collection
- The Collection whose contents should be added.
- The lazylist created or added to.
add
public static Object add(Object list,
Object item)
Add an item to a LazyList
list
- The list to add to or null if none yet created.item
- The item to add.
- The lazylist created or added to.
add
public static Object add(Object list,
int index,
Object item)
Add an item to a LazyList
list
- The list to add to or null if none yet created.index
- The index to add the item at.item
- The item to add.
- The lazylist created or added to.
addCollection
public static Object addCollection(Object list,
Collection collection)
Add the contents of a Collection to a LazyList
list
- The list to add to or null if none yet created.collection
- The Collection whose contents should be added.
- The lazylist created or added to.
clone
public static Object clone(Object list)
contains
public static boolean contains(Object list,
Object item)
ensureSize
public static Object ensureSize(Object list,
int initialSize)
get
public static Object get(Object list,
int i)
Get item from the list
list
- A LazyList returned from LazyList.add(Object) or nulli
- int index
getList
public static List getList(Object list)
Get the real List from a LazyList.
list
- A LazyList returned from LazyList.add(Object)
- The List of added items, which may be an EMPTY_LIST
or a SingletonList.
getList
public static List getList(Object list,
boolean nullForEmpty)
Get the real List from a LazyList.
list
- A LazyList returned from LazyList.add(Object) or nullnullForEmpty
- If true, null is returned instead of an
empty list.
- The List of added items, which may be null, an EMPTY_LIST
or a SingletonList.
iterator
public static Iterator iterator(Object list)
listIterator
public static ListIterator listIterator(Object list)
remove
public static Object remove(Object list,
Object o)
remove
public static Object remove(Object list,
int i)
size
public static int size(Object list)
The size of a lazy List
list
- A LazyList returned from LazyList.add(Object) or null
toString
public static String toString(Object list)
toStringArray
public static String[] toStringArray(Object list)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.