Class WeldCollections


  • public class WeldCollections
    extends Object
    Collection utilities.
    Author:
    Jozef Hartinger
    • Field Detail

      • EMPTY_ARRAY_SET_MULTIMAP

        public static final Map<Object,​List<Object>> EMPTY_ARRAY_SET_MULTIMAP
    • Method Detail

      • immutableSet

        public static <T> Set<T> immutableSet​(Set<T> set)
        Returns an immutable view of a given set. If the given set is empty, a shared instance is returned. If the given set is an instance of ArraySet, it is trimmed.
      • immutableGuavaSet

        public static <T> Set<T> immutableGuavaSet​(Set<T> set)
        Returns an immutable view of a given set. If the given set is empty, a shared instance is returned.
      • immutableList

        public static <T> List<T> immutableList​(List<T> list)
        Returns an immutable view of a given list. If the given list is empty, a shared instance is returned. If the given list is an instance of ArrayList, it is trimmed.
      • immutableGuavaList

        public static <T> List<T> immutableGuavaList​(List<T> list)
        Returns an immutable view of a given list. If the given list is empty, a shared instance is returned.
      • immutableMap

        public static <K,​V> Map<K,​V> immutableMap​(Map<K,​V> map)
        Returns an immutable view of a given map. If the given map is empty, a shared instance is returned.
      • toMultiRowString

        public static String toMultiRowString​(Collection<?> collection)
        Returns the supplied collection as a multi-row string with every toString() of every element of the collection in its own row. Example: toMultiRowString(Arrays.asList("aaa", "bbb", "ccc")) will return:
           - aaa,
           - bbb,
           - ccc
         
      • addAll

        public static <E> boolean addAll​(Collection<E> collection,
                                         E... elements)
        Parameters:
        collection -
        elements -
        Returns:
        true if the collection changed as a result of the call
      • addIfNotNull

        public static <T> boolean addIfNotNull​(Collection<T> collection,
                                               T element)
      • putIfAbsent

        public static <K,​V> V putIfAbsent​(ConcurrentMap<K,​V> map,
                                                K key,
                                                V value)
        Utility method for working with maps. Unlike Map.putIfAbsent(Object, Object) this method always returns the value that ends up store in the map which is either the old value (if any was present) or the new value (if it was stored in the map).
        Parameters:
        map - the map
        key - the key
        value - the value
        Returns:
        the value that ends up store in the map which is either the old value (if any was present) or the new value (if it was stored in the map)