Class Collect


  • public class Collect
    extends Object
    A set of utilities for more easily creating various kinds of collections.
    • Constructor Detail

      • Collect

        private Collect()
    • Method Detail

      • fixedSizeMap

        public static <K,​V> Map<K,​V> fixedSizeMap​(int maximumNumberOfEntries)
        Create a fixed sized Map that removes the least-recently used entry when the map becomes too large. The supplied maximumNumberOfEntries should be a power of 2 to efficiently make efficient use of memory. If not, the resulting map will be able to contain no more than maximumNumberOfEntries entries, but the underlying map will have a capacity that is the next power of larger than the supplied maximumNumberOfEntries value so that it can hold the required number of entries.
        Parameters:
        maximumNumberOfEntries - the maximum number of entries allowed in the map; should be a power of 2
        Returns:
        the map that is limited in size by the specified number of entries; never null
      • unmodifiableSet

        public static <T,​V> Set<T> unmodifiableSet​(Function<V,​T> extractor,
                                                         V... values)
      • unmodifiableSet

        public static <T,​V> Set<T> unmodifiableSet​(Function<V,​T> extractor,
                                                         Collection<V> values)
      • unmodifiableSet

        public static <T> Set<T> unmodifiableSet​(Set<T> values,
                                                 T... additionalValues)
      • unmodifiableSet

        public static <T> Set<T> unmodifiableSet​(T... values)
      • unmodifiableSet

        public static <T> Set<T> unmodifiableSet​(Collection<T> values)
      • unmodifiableSet

        public static <T> Set<T> unmodifiableSet​(Set<T> values)
      • unmodifiableSet

        public static <T> Set<T> unmodifiableSet​(Iterator<T> values)
      • arrayListOf

        public static <T> List<T> arrayListOf​(T[] values)
      • arrayListOf

        public static <T> List<T> arrayListOf​(T first,
                                              T... additional)
      • arrayListOf

        public static <T> List<T> arrayListOf​(Iterable<T> values)
      • mapOf

        public static <K,​V> Map<K,​V> mapOf​(K key,
                                                       V value)
      • hashMapOf

        public static <K,​V> Map<K,​V> hashMapOf​(K key,
                                                           V value)
      • hashMapOf

        public static <K,​V> Map<K,​V> hashMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2)
      • hashMapOf

        public static <K,​V> Map<K,​V> hashMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2,
                                                           K key3,
                                                           V value3)
      • hashMapOf

        public static <K,​V> Map<K,​V> hashMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2,
                                                           K key3,
                                                           V value3,
                                                           K key4,
                                                           V value4)
      • hashMapOf

        public static <K,​V> Map<K,​V> hashMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2,
                                                           K key3,
                                                           V value3,
                                                           K key4,
                                                           V value4,
                                                           K key5,
                                                           V value5)
      • hashMapOf

        public static <K,​V> Map<K,​V> hashMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2,
                                                           K key3,
                                                           V value3,
                                                           K key4,
                                                           V value4,
                                                           K key5,
                                                           V value5,
                                                           K key6,
                                                           V value6)
      • linkMapOf

        public static <K,​V> Map<K,​V> linkMapOf​(K key,
                                                           V value)
      • linkMapOf

        public static <K,​V> Map<K,​V> linkMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2)
      • linkMapOf

        public static <K,​V> Map<K,​V> linkMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2,
                                                           K key3,
                                                           V value3)
      • linkMapOf

        public static <K,​V> Map<K,​V> linkMapOf​(K key1,
                                                           V value1,
                                                           K key2,
                                                           V value2,
                                                           K key3,
                                                           V value3,
                                                           K key4,
                                                           V value4)
      • set

        public static <T> void set​(List<T> list,
                                   int index,
                                   T value,
                                   T defaultValue)
        Set the value at the given position in the list, expanding the list as required to accommodate the new position.

        This is not a thread-safe operation

        Parameters:
        list - the list to be modified
        index - the index position of the new value
        value - the value
        defaultValue - the value used for intermediate positions when expanding the list; may be null
      • minus

        public static <T> Set<T> minus​(Set<T> subtrahend,
                                       Set<T> minuend)
        Remove the content of one set from an another one.
        Parameters:
        subtrahend - the main set
        minuend - the elements to be removed