public class LazyList extends Object implements Cloneable, Serializable
Collections.EMPTY_LIST
or
Collections.singletonList(Object)
where possible.
LazyList works by passing an opaque representation of the list in
and out of all the LazyList methods. This opaque object is either
null for an empty list, an Object for a list with a single entry
or an ArrayList
for a list of items.
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.
List
,
Serialized FormModifier and Type | Method and Description |
---|---|
static Object |
add(Object list,
int index,
Object item)
Add an item to a LazyList
|
static Object |
add(Object list,
Object item)
Add an item to a LazyList
|
static Object |
addArray(Object list,
Object[] array)
Add the contents of an array 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)
Ensure the capacity of the underlying list.
|
static <E> E |
get(Object list,
int i)
Get item from the list
|
static <E> List<E> |
getList(Object list)
Get the real List from a LazyList.
|
static <E> List<E> |
getList(Object list,
boolean nullForEmpty)
Get the real List from a LazyList.
|
static boolean |
hasEntry(Object list)
Simple utility method to test if List has at least 1 entry.
|
static boolean |
isEmpty(Object list)
Simple utility method to test if List is empty
|
static <E> Iterator<E> |
iterator(Object list) |
static <E> ListIterator<E> |
listIterator(Object list) |
static Object |
remove(Object list,
int i) |
static Object |
remove(Object list,
Object o) |
static int |
size(Object list)
The size of a lazy List
|
static Object |
toArray(Object list,
Class<?> clazz)
Convert a lazylist to an array
|
static String |
toString(Object list) |
static String[] |
toStringArray(Object list) |
public static Object add(Object list, Object item)
list
- The list to add to or null if none yet created.item
- The item to add.public static Object add(Object list, int index, Object item)
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.public static Object addCollection(Object list, Collection<?> collection)
list
- The list to add to or null if none yet created.collection
- The Collection whose contents should be added.public static Object addArray(Object list, Object[] array)
list
- The list to add to or null if none yet created.array
- The array whose contents should be added.public static Object ensureSize(Object list, int initialSize)
public static <E> List<E> getList(Object list)
list
- A LazyList returned from LazyList.add(Object)public static <E> List<E> getList(Object list, boolean nullForEmpty)
list
- A LazyList returned from LazyList.add(Object) or nullnullForEmpty
- If true, null is returned instead of an
empty list.public static boolean hasEntry(Object list)
public static boolean isEmpty(Object list)
public static Object toArray(Object list, Class<?> clazz)
list
- The list to convertclazz
- The class of the array, which may be a primitive typepublic static int size(Object list)
list
- A LazyList returned from LazyList.add(Object) or nullpublic static <E> E get(Object list, int i)
list
- A LazyList returned from LazyList.add(Object) or nulli
- int indexpublic static <E> ListIterator<E> listIterator(Object list)
Copyright © 1995-2015 Webtide. All Rights Reserved.