A List helper class that attempts to avoid unnecessary 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(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.
java.util.List
| Modifier and Type | Field and Description |
|---|---|
| private static final String[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Object | |
| public static Object | |
| public static Object | |
| public static Object | Returns: The lazylist created or added to.The list to add to or null if none yet created. list, Collection<?> The Collection whose contents should be added. collection)Add the contents of a Collection to a LazyList |
| public static Object | |
| public static boolean | |
| public static Object | Returns: the new List with new sizethe list to grow list, int the size to grow to initialSize)Ensure the capacity of the underlying list. |
| public static < the list entry type E> E | |
| public static < the list entry type E> List | |
| public static < the list entry type E> List | |
| public static boolean | |
| public static boolean | |
| public static <E> Iterator | |
| public static <E> ListIterator | |
| public static Object | |
| public static Object | |
| public static int | |
| public static Object | |
| public static String | |
| public static String[] |
| __EMPTY_STRING_ARRAY | back to summary |
|---|---|
| private static final String[] __EMPTY_STRING_ARRAY | |
| LazyList | back to summary |
|---|---|
| private LazyList() | |
| add | back to summary |
|---|---|
| public static Object add(Object list, Object item) Add an item to a LazyList
| |
| add | back to summary |
|---|---|
| public static Object add(Object list, int index, Object item) Add an item to a LazyList
| |
| addArray | back to summary |
|---|---|
| public static Object addArray(Object list, Object[] array) Add the contents of an array to a LazyList | |
| addCollection | back to summary |
|---|---|
| public static Object addCollection(Object list, Collection<?> collection) Add the contents of a Collection to a LazyList
| |
| clone | back to summary |
|---|---|
| public static Object clone(Object list) | |
| contains | back to summary |
|---|---|
| public static boolean contains(Object list, Object item) | |
| ensureSize | back to summary |
|---|---|
| public static Object ensureSize(Object list, int initialSize) Ensure the capacity of the underlying list. | |
| get | back to summary |
|---|---|
| public static <E> E get(Object list, int i) Get item from the list
| |
| getList | back to summary |
|---|---|
| public static <E> List Get the real List from a LazyList. | |
| getList | back to summary |
|---|---|
| public static <E> List Get the real List from a LazyList.
| |
| hasEntry | back to summary |
|---|---|
| public static boolean hasEntry(Object list) Simple utility method to test if List has at least 1 entry. | |
| isEmpty | back to summary |
|---|---|
| public static boolean isEmpty(Object list) Simple utility method to test if List is empty | |
| iterator | back to summary |
|---|---|
public static <E> Iterator
| |
| listIterator | back to summary |
|---|---|
public static <E> ListIterator
| |
| remove | back to summary |
|---|---|
| public static Object remove(Object list, Object o) | |
| remove | back to summary |
|---|---|
| public static Object remove(Object list, int i) | |
| size | back to summary |
|---|---|
| public static int size(Object list) The size of a lazy List
| |
| toArray | back to summary |
|---|---|
| public static Object toArray(Object list, Class<?> clazz) Convert a lazylist to an array | |
| toString | back to summary |
|---|---|
| public static String toString(Object list) | |
| toStringArray | back to summary |
|---|---|
| public static String[] toStringArray(Object list) | |