LazyList

Lazy List creation. <p> 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 {@link Collections#EMPTY_LIST} or {@link Collections#singletonList(Object)} where possible. </p> <p> 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 {@link ArrayList} for a list of items. </p> <strong>Usage</strong>

<pre> Object lazylist = null; while (loopCondition) { Object item = getItem(); if (item.isToBeAdded()) lazylist = LazyList.add(lazylist, item); } return LazyList.getList(lazylist); </pre>

An ArrayList of default size is used as the initial LazyList.

@see java.util.List

Members

Static functions

add
Object add(Object list, Object item)

Add an item to a LazyList

getList
List!E getList(Object list, bool nullForEmpty)

Get the real List from a LazyList.

size
int size(List!(T) list)

The size of a lazy List

Meta