Class LazyList

java.lang.Object
org.eclipse.jetty.util.LazyList
All Implemented Interfaces:
Serializable, Cloneable

public class LazyList extends Object implements Cloneable, Serializable
Lazy List creation.

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.

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: