类 CollectionHelper


  • public final class CollectionHelper
    extends Object
    Various help for handling collections.
    作者:
    Gavin King, Steve Ebersole
    • 方法详细资料

      • mapOfSize

        public static <K,​V> Map<K,​V> mapOfSize​(int size)
        Build a properly sized map, especially handling load size and load factor to prevent immediate resizing.

        Especially helpful for copy map contents.

        参数:
        size - The size to make the map.
        返回:
        The sized map.
      • determineProperSizing

        public static int determineProperSizing​(Map original)
        Given a map, determine the proper initial size for a new Map to hold the same number of values. Specifically we want to account for load size and load factor to prevent immediate resizing.
        参数:
        original - The original map
        返回:
        The proper size.
      • makeCopy

        public static <X,​Y> Map<X,​Y> makeCopy​(Map<X,​Y> map)
      • makeCopy

        public static <K,​V> HashMap<K,​V> makeCopy​(Map<K,​V> original,
                                                              Function<K,​K> keyTransformer,
                                                              Function<V,​V> valueTransformer)
      • makeMap

        public static <K,​V> Map<K,​V> makeMap​(Collection<V> collection,
                                                         Function<V,​K> keyProducer)
      • makeMap

        public static <K,​V,​E> Map<K,​V> makeMap​(Collection<E> collection,
                                                                 Function<E,​K> keyProducer,
                                                                 Function<E,​V> valueProducer)
      • determineProperSizing

        public static int determineProperSizing​(Set original)
        Given a set, determine the proper initial size for a new set to hold the same number of values. Specifically we want to account for load size and load factor to prevent immediate resizing.
        参数:
        original - The original set
        返回:
        The proper size.
      • determineProperSizing

        public static int determineProperSizing​(int numberOfElements)
        Determine the proper initial size for a new collection in order for it to hold the given a number of elements. Specifically we want to account for load size and load factor to prevent immediate resizing.
        参数:
        numberOfElements - The number of elements to be stored.
        返回:
        The proper size.
      • concurrentMap

        public static <K,​V> ConcurrentHashMap<K,​V> concurrentMap​(int expectedNumberOfElements)
        Create a properly sized ConcurrentHashMap based on the given expected number of elements.
        类型参数:
        K - The map key type
        V - The map value type
        参数:
        expectedNumberOfElements - The expected number of elements for the created map
        返回:
        The created map.
      • concurrentMap

        public static <K,​V> ConcurrentHashMap<K,​V> concurrentMap​(int expectedNumberOfElements,
                                                                             float loadFactor)
        Create a properly sized ConcurrentHashMap based on the given expected number of elements and an explicit load factor
        类型参数:
        K - The map key type
        V - The map value type
        参数:
        expectedNumberOfElements - The expected number of elements for the created map
        loadFactor - The collection load factor
        返回:
        The created map.
      • arrayList

        public static <T> ArrayList<T> arrayList​(int anticipatedSize)
      • makeCopy

        public static <T> Set<T> makeCopy​(Set<T> source)
      • isEmpty

        public static boolean isEmpty​(Collection collection)
      • isEmpty

        public static boolean isEmpty​(Map map)
      • isNotEmpty

        public static boolean isNotEmpty​(Collection collection)
      • isNotEmpty

        public static boolean isNotEmpty​(Map map)
      • isEmpty

        public static boolean isEmpty​(Object[] objects)