Class LazyList

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    @Deprecated(since="2021-05-27")
    public class LazyList
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    Deprecated.
    The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.
    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:
    List, Serialized Form
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.lang.Object add​(java.lang.Object list, int index, java.lang.Object item)
      Deprecated.
      Add an item to a LazyList
      static java.lang.Object add​(java.lang.Object list, java.lang.Object item)
      Deprecated.
      Add an item to a LazyList
      static java.lang.Object addArray​(java.lang.Object list, java.lang.Object[] array)
      Deprecated.
      Add the contents of an array to a LazyList
      static java.lang.Object addCollection​(java.lang.Object list, java.util.Collection<?> collection)
      Deprecated.
      Add the contents of a Collection to a LazyList
      static java.lang.Object clone​(java.lang.Object list)
      Deprecated.
       
      static boolean contains​(java.lang.Object list, java.lang.Object item)
      Deprecated.
       
      static java.lang.Object ensureSize​(java.lang.Object list, int initialSize)
      Deprecated.
      Ensure the capacity of the underlying list.
      static <E> E get​(java.lang.Object list, int i)
      Deprecated.
      Get item from the list
      static <E> java.util.List<E> getList​(java.lang.Object list)
      Deprecated.
      Get the real List from a LazyList.
      static <E> java.util.List<E> getList​(java.lang.Object list, boolean nullForEmpty)
      Deprecated.
      Get the real List from a LazyList.
      static boolean hasEntry​(java.lang.Object list)
      Deprecated.
      Simple utility method to test if List has at least 1 entry.
      static boolean isEmpty​(java.lang.Object list)
      Deprecated.
      Simple utility method to test if List is empty
      static <E> java.util.Iterator<E> iterator​(java.lang.Object list)
      Deprecated.
       
      static <E> java.util.ListIterator<E> listIterator​(java.lang.Object list)
      Deprecated.
       
      static java.lang.Object remove​(java.lang.Object list, int i)
      Deprecated.
       
      static java.lang.Object remove​(java.lang.Object list, java.lang.Object o)
      Deprecated.
       
      static int size​(java.lang.Object list)
      Deprecated.
      The size of a lazy List
      static java.lang.Object toArray​(java.lang.Object list, java.lang.Class<?> clazz)
      Deprecated.
      Convert a lazylist to an array
      static java.lang.String toString​(java.lang.Object list)
      Deprecated.
       
      static java.lang.String[] toStringArray​(java.lang.Object list)
      Deprecated.
       
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • add

        public static java.lang.Object add​(java.lang.Object list,
                                           java.lang.Object item)
        Deprecated.
        Add an item to a LazyList
        Parameters:
        list - The list to add to or null if none yet created.
        item - The item to add.
        Returns:
        The lazylist created or added to.
      • add

        public static java.lang.Object add​(java.lang.Object list,
                                           int index,
                                           java.lang.Object item)
        Deprecated.
        Add an item to a LazyList
        Parameters:
        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.
        Returns:
        The lazylist created or added to.
      • addCollection

        public static java.lang.Object addCollection​(java.lang.Object list,
                                                     java.util.Collection<?> collection)
        Deprecated.
        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

        public static java.lang.Object addArray​(java.lang.Object list,
                                                java.lang.Object[] array)
        Deprecated.
        Add the contents of an array to a LazyList
        Parameters:
        list - The list to add to or null if none yet created.
        array - The array whose contents should be added.
        Returns:
        The lazylist created or added to.
      • ensureSize

        public static java.lang.Object ensureSize​(java.lang.Object list,
                                                  int initialSize)
        Deprecated.
        Ensure the capacity of the underlying list.
        Parameters:
        list - the list to grow
        initialSize - the size to grow to
        Returns:
        the new List with new size
      • remove

        public static java.lang.Object remove​(java.lang.Object list,
                                              java.lang.Object o)
        Deprecated.
      • remove

        public static java.lang.Object remove​(java.lang.Object list,
                                              int i)
        Deprecated.
      • getList

        public static <E> java.util.List<E> getList​(java.lang.Object list)
        Deprecated.
        Get the real List from a LazyList.
        Type Parameters:
        E - the list entry type
        Parameters:
        list - A LazyList returned from LazyList.add(Object)
        Returns:
        The List of added items, which may be an EMPTY_LIST or a SingletonList.
      • getList

        public static <E> java.util.List<E> getList​(java.lang.Object list,
                                                    boolean nullForEmpty)
        Deprecated.
        Get the real List from a LazyList.
        Type Parameters:
        E - the list entry type
        Parameters:
        list - A LazyList returned from LazyList.add(Object) or null
        nullForEmpty - 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

        public static boolean hasEntry​(java.lang.Object list)
        Deprecated.
        Simple utility method to test if List has at least 1 entry.
        Parameters:
        list - a LazyList, List or Object
        Returns:
        true if not-null and is not empty
      • isEmpty

        public static boolean isEmpty​(java.lang.Object list)
        Deprecated.
        Simple utility method to test if List is empty
        Parameters:
        list - a LazyList, List or Object
        Returns:
        true if null or is empty
      • toStringArray

        public static java.lang.String[] toStringArray​(java.lang.Object list)
        Deprecated.
      • toArray

        public static java.lang.Object toArray​(java.lang.Object list,
                                               java.lang.Class<?> clazz)
        Deprecated.
        Convert a lazylist to an array
        Parameters:
        list - The list to convert
        clazz - The class of the array, which may be a primitive type
        Returns:
        array of the lazylist entries passed in
      • size

        public static int size​(java.lang.Object list)
        Deprecated.
        The size of a lazy List
        Parameters:
        list - A LazyList returned from LazyList.add(Object) or null
        Returns:
        the size of the list.
      • get

        public static <E> E get​(java.lang.Object list,
                                int i)
        Deprecated.
        Get item from the list
        Type Parameters:
        E - the list entry type
        Parameters:
        list - A LazyList returned from LazyList.add(Object) or null
        i - int index
        Returns:
        the item from the list.
      • contains

        public static boolean contains​(java.lang.Object list,
                                       java.lang.Object item)
        Deprecated.
      • clone

        public static java.lang.Object clone​(java.lang.Object list)
        Deprecated.
      • toString

        public static java.lang.String toString​(java.lang.Object list)
        Deprecated.
      • iterator

        public static <E> java.util.Iterator<E> iterator​(java.lang.Object list)
        Deprecated.
      • listIterator

        public static <E> java.util.ListIterator<E> listIterator​(java.lang.Object list)
        Deprecated.