Class FlatLists


  • public class FlatLists
    extends java.lang.Object
    Space-efficient, comparable, immutable lists.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FlatLists.AbstractFlatList<T>
      Base class for flat lists.
      private static class  FlatLists.ComparableEmptyList<T>
      Empty list that implements the Comparable interface.
      static interface  FlatLists.ComparableList<T>
      List that is also comparable.
      (package private) static class  FlatLists.ComparableListImpl<T extends java.lang.Comparable<T>>
      Wrapper around a list that makes it implement the Comparable interface using lexical ordering.
      protected static class  FlatLists.Flat1List<T>
      List that stores its one elements in the one members of the class.
      protected static class  FlatLists.Flat2List<T>
      List that stores its two elements in the two members of the class.
      protected static class  FlatLists.Flat3List<T>
      List that stores its three elements in the three members of the class.
      protected static class  FlatLists.Flat4List<T>
      List that stores its four elements in the four members of the class.
      protected static class  FlatLists.Flat5List<T>
      List that stores its five elements in the five members of the class.
      protected static class  FlatLists.Flat6List<T>
      List that stores its six elements in the six members of the class.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FlatLists()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static <E> com.google.common.collect.ImmutableList<E> append​(com.google.common.collect.ImmutableList<E> list, E e)
      Returns a list that consists of a given list plus an element, guaranteed to be an ImmutableList.
      static <E> java.util.List<E> append​(java.util.List<E> list, E e)
      Returns a list that consists of a given list plus an element.
      static <K,​V>
      com.google.common.collect.ImmutableMap<K,​V>
      append​(java.util.Map<K,​V> map, K k, V v)
      Returns a map that consists of a given map plus an (key, value), guaranteed to be an ImmutableMap.
      static <T> java.util.List<T> copy​(T... t)
      Deprecated.
      static <T extends java.lang.Comparable>
      java.util.List<T>
      copyOf​(T... t)
      Creates a memory-, CPU- and cache-efficient comparable immutable list, always copying the contents.
      private static <T extends java.lang.Object & java.lang.Comparable>
      FlatLists.ComparableList<T>
      flatList_​(T[] t, boolean copy)
      Creates a memory-, CPU- and cache-efficient comparable immutable list, optionally copying the list.
      private static <T> java.util.List<T> flatListNotComparable​(T[] t)
      Creates a memory-, CPU- and cache-efficient immutable list, always copying the list.
      static <T> FlatLists.ComparableList<T> of()
      Creates a flat list with 0 elements.
      static <T> java.util.List<T> of​(java.util.List<T> t)
      Creates a memory-, CPU- and cache-efficient immutable list from an existing list.
      static <T> java.util.List<T> of​(T t0)
      Creates a flat list with 1 element.
      static <T extends java.lang.Comparable>
      java.util.List<T>
      of​(T... t)
      Creates a memory-, CPU- and cache-efficient immutable list.
      static <T> java.util.List<T> of​(T t0, T t1)
      Creates a flat list with 2 elements.
      static <T> java.util.List<T> of​(T t0, T t1, T t2)
      Creates a flat list with 3 elements.
      static <T> java.util.List<T> of​(T t0, T t1, T t2, T t3)
      Creates a flat list with 4 elements.
      static <T> java.util.List<T> of​(T t0, T t1, T t2, T t3, T t4)
      Creates a flat list with 6 elements.
      static <T> java.util.List<T> of​(T t0, T t1, T t2, T t3, T t4, T t5)
      Creates a flat list with 6 elements.
      private static <T> FlatLists.ComparableList<T> of_​(java.util.List<T> t)  
      static <T extends java.lang.Comparable>
      FlatLists.ComparableList<T>
      ofComparable​(java.util.List<T> t)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FlatLists

        private FlatLists()
    • Method Detail

      • of

        public static <T> java.util.List<T> of​(T t0)
        Creates a flat list with 1 element.
      • of

        public static <T> java.util.List<T> of​(T t0,
                                               T t1)
        Creates a flat list with 2 elements.
      • of

        public static <T> java.util.List<T> of​(T t0,
                                               T t1,
                                               T t2)
        Creates a flat list with 3 elements.
      • of

        public static <T> java.util.List<T> of​(T t0,
                                               T t1,
                                               T t2,
                                               T t3)
        Creates a flat list with 4 elements.
      • of

        public static <T> java.util.List<T> of​(T t0,
                                               T t1,
                                               T t2,
                                               T t3,
                                               T t4)
        Creates a flat list with 6 elements.
      • of

        public static <T> java.util.List<T> of​(T t0,
                                               T t1,
                                               T t2,
                                               T t3,
                                               T t4,
                                               T t5)
        Creates a flat list with 6 elements.
      • of

        public static <T extends java.lang.Comparable> java.util.List<T> of​(T... t)
        Creates a memory-, CPU- and cache-efficient immutable list.
        Type Parameters:
        T - Element type
        Parameters:
        t - Array of members of list
        Returns:
        List containing the given members
      • copy

        @Deprecated
        public static <T> java.util.List<T> copy​(T... t)
        Deprecated.
        Creates a memory-, CPU- and cache-efficient immutable list, always copying the contents.
        Type Parameters:
        T - Element type
        Parameters:
        t - Array of members of list
        Returns:
        List containing the given members
      • copyOf

        public static <T extends java.lang.Comparable> java.util.List<T> copyOf​(T... t)
        Creates a memory-, CPU- and cache-efficient comparable immutable list, always copying the contents.

        The elements are comparable, and so is the returned list. Elements may be null.

        Type Parameters:
        T - Element type
        Parameters:
        t - Array of members of list
        Returns:
        List containing the given members
      • copyOf

        public static <T> java.util.List<T> copyOf​(T... t)
        Creates a memory-, CPU- and cache-efficient immutable list, always copying the contents.

        The elements need not be comparable, and the returned list may not implement Comparable. Elements may be null.

        Type Parameters:
        T - Element type
        Parameters:
        t - Array of members of list
        Returns:
        List containing the given members
      • flatList_

        private static <T extends java.lang.Object & java.lang.Comparable> FlatLists.ComparableList<T> flatList_​(T[] t,
                                                                                                                 boolean copy)
        Creates a memory-, CPU- and cache-efficient comparable immutable list, optionally copying the list.
        Parameters:
        copy - Whether to always copy the list
        t - Array of members of list
        Returns:
        List containing the given members
      • flatListNotComparable

        private static <T> java.util.List<T> flatListNotComparable​(T[] t)
        Creates a memory-, CPU- and cache-efficient immutable list, always copying the list.
        Parameters:
        t - Array of members of list
        Returns:
        List containing the given members
      • of

        public static <T> java.util.List<T> of​(java.util.List<T> t)
        Creates a memory-, CPU- and cache-efficient immutable list from an existing list. The list is always copied.
        Type Parameters:
        T - Element type
        Parameters:
        t - Array of members of list
        Returns:
        List containing the given members
      • ofComparable

        public static <T extends java.lang.Comparable> FlatLists.ComparableList<T> ofComparable​(java.util.List<T> t)
      • append

        public static <E> java.util.List<E> append​(java.util.List<E> list,
                                                   E e)
        Returns a list that consists of a given list plus an element.
      • append

        public static <E> com.google.common.collect.ImmutableList<E> append​(com.google.common.collect.ImmutableList<E> list,
                                                                            E e)
        Returns a list that consists of a given list plus an element, guaranteed to be an ImmutableList.
      • append

        public static <K,​V> com.google.common.collect.ImmutableMap<K,​V> append​(java.util.Map<K,​V> map,
                                                                                           K k,
                                                                                           V v)
        Returns a map that consists of a given map plus an (key, value), guaranteed to be an ImmutableMap.