Package org.eclipse.jetty.util
Class LazyList
java.lang.Object
org.eclipse.jetty.util.LazyList
- All Implemented Interfaces:
Serializable
,Cloneable
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.
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:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Add an item to a LazyListstatic Object
Add an item to a LazyListstatic Object
Add the contents of an array to a LazyListstatic Object
addCollection
(Object list, Collection<?> collection) Add the contents of a Collection to a LazyListstatic Object
static boolean
static Object
ensureSize
(Object list, int initialSize) Ensure the capacity of the underlying list.static <E> E
Get item from the liststatic <E> List
<E> Get the real List from a LazyList.static <E> List
<E> Get the real List from a LazyList.static boolean
Simple utility method to test if List has at least 1 entry.static boolean
Simple utility method to test if List is emptystatic <E> Iterator
<E> static <E> ListIterator
<E> listIterator
(Object list) static Object
static Object
static int
The size of a lazy Liststatic Object
Convert a lazylist to an arraystatic String
static String[]
toStringArray
(Object list)
-
Method Details
-
add
-
add
-
addCollection
Add the contents of a Collection to a LazyList- Parameters:
list
- The list to add to or null if none yet created.collection
- The Collection whose contents should be added.- Returns:
- The lazylist created or added to.
-
addArray
-
ensureSize
-
remove
-
remove
-
getList
-
getList
Get the real List from a LazyList.- Type Parameters:
E
- the list entry type- Parameters:
list
- A LazyList returned from LazyList.add(Object) or nullnullForEmpty
- If true, null is returned instead of an empty list.- Returns:
- The List of added items, which may be null, an EMPTY_LIST or a SingletonList.
-
hasEntry
-
isEmpty
-
toStringArray
-
toArray
-
size
The size of a lazy List- Parameters:
list
- A LazyList returned from LazyList.add(Object) or null- Returns:
- the size of the list.
-
get
Get item from the list- Type Parameters:
E
- the list entry type- Parameters:
list
- A LazyList returned from LazyList.add(Object) or nulli
- int index- Returns:
- the item from the list.
-
contains
-
clone
-
toString
-
iterator
-
listIterator
-