java.lang.Object
de.cuioss.tools.collect.CollectionLiterals
Overview
Provides a number of methods simplifying the task of creating populatedCollections. In essence its doing the
same compared to the corresponding com.google.common.collect types but with
different semantics (like naming, types) and is designed as a one-stop
utility class. It differentiates between the subtypes and mutability /
immutability. This class is complementary to the corresponding guava types.
Lists
assertMutable(CollectionLiterals#mutableList("1"));
assertMutable(CollectionLiterals#mutableList("1", "2"));
assertMutable(CollectionLiterals#mutableList(Arrays.asList("1", "2").stream()));
assertImmutable(CollectionLiterals#immutableList("1"));
assertImmutable(CollectionLiterals#immutableList("1", "2"));
assertImmutable(CollectionLiterals#immutableList(Arrays.asList("1", "2").stream()));
Sets
assertMutable(CollectionLiterals#mutableSet("1"));
assertMutable(CollectionLiterals#mutableSet("1", "2"));
assertMutable(CollectionLiterals#mutableSet(Arrays.asList("1", "2").stream()));
assertImmutable(CollectionLiterals#immutableSet("1"));
assertImmutable(CollectionLiterals#immutableSet("1", "2"));
assertImmutable(CollectionLiterals#immutableSet(Arrays.asList("1", "2").stream()));
Maps
assertMutable(CollectionLiterals#mutableMap());
assertMutable(CollectionLiterals#mutableMap("1", "1-1"));
assertMutable(CollectionLiterals#mutableMap("1", "1-1", "2", "2-2", "3", "3-3", "4", "4-4"));
assertImmutable(CollectionLiterals#immutableMap());
assertImmutable(CollectionLiterals#immutableMap("1", "1-1"));
assertImmutable(CollectionLiterals#immutableMap("1", "1-1", "2", "2-2", "3", "3-3", "4", "4-4"));
- Author:
- Oliver Wolff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> List<E>Creates an immutableListinstance.static <E> List<E>immutableList(E element) Creates an immutableListinstance containing the given element.static <E> List<E>immutableList(E... elements) Creates an immutableListinstance containing the given elements.static <E> List<E>immutableList(Iterable<? extends E> elements) Creates an immutableListinstance containing the given elements.static <E> List<E>immutableList(Collection<? extends E> elements) Creates an immutableListinstance containing the given elements.static <E> List<E>immutableList(Iterator<? extends E> elements) Creates an immutableListinstance containing the given elements.static <E> List<E>immutableList(Stream<? extends E> elements) Creates an immutableListinstance containing the given elements.static <K,V> Map<K, V> immutableMap.static <K,V> Map<K, V> immutableMap(Map<K, V> source) Shorthand toCollections.unmodifiableMap(Map)static <K,V> Map<K, V> immutableMap(Stream<Map.Entry<K, V>> elements) Copies the entries of the given map stream into a new map which is then returned as an unmodifiable map.static <K,V> Map<K, V> immutableMap(K k, V v) Convenience method for the inline creation of a map with valuesstatic <K,V> Map<K, V> immutableMap(K k1, V v1, K k2, V v2) Convenience method for the inline creation of a map with valuesstatic <K,V> Map<K, V> immutableMap(K k1, V v1, K k2, V v2, K k3, V v3) Convenience method for the inline creation of a map with valuesstatic <K,V> Map<K, V> immutableMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Convenience method for the inline creation of a map with valuesstatic <E> Set<E>immutableSet.static <E> Set<E>immutableSet(E element) Creates an immutableSetinstance containing the given elements.static <E> Set<E>immutableSet(E... elements) Creates an immutableSetinstance containing the given elements.static <E> Set<E>immutableSet(Iterable<? extends E> elements) Creates an immutableSetinstance containing the given elements.static <E> Set<E>immutableSet(Iterator<? extends E> elements) Creates an immutableSetinstance containing the given elements.static <E> Set<E>immutableSet(Stream<? extends E> elements) Creates an immutableSetinstance containing the given elements.static <E> SortedSet<E>immutableSortedSet.static <E> SortedSet<E>immutableSortedSet(E element) Creates an immutableSortedSetinstance containing the given elements.static <E> SortedSet<E>immutableSortedSet(E... elements) Creates an immutableSortedSetinstance containing the given elements.static <E> SortedSet<E>immutableSortedSet(Iterable<? extends E> elements) Creates an immutableSortedSetinstance containing the given elements.static <E> SortedSet<E>immutableSortedSet(Iterator<? extends E> elements) Creates an immutableSortedSetinstance containing the given elements.static <E> SortedSet<E>immutableSortedSet(Stream<? extends E> elements) Creates an immutableSortedSetinstance containing the given elements.static <E> List<E>mutableList.static <E> List<E>mutableList(E element) Creates a mutableListinstance containing the given elementstatic <E> List<E>mutableList(E... elements) Creates a mutableListinstance containing the given elements.static <E> List<E>mutableList(Iterable<? extends E> elements) Creates a mutableListinstance containing the given elements.static <E> List<E>mutableList(Collection<? extends E> elements) Creates a mutableListinstance containing the given elements.static <E> List<E>mutableList(Iterator<? extends E> elements) Creates a mutableListinstance containing the given elements.static <E> List<E>mutableList(Stream<? extends E> elements) Creates a mutableListinstance containing the given elements.static <K,V> Map<K, V> mutableMap.static <K,V> Map<K, V> mutableMap(K k, V v) Convenience method for the inline creation of a map with valuesstatic <K,V> Map<K, V> mutableMap(K k1, V v1, K k2, V v2) Convenience method for the inline creation of a map with valuesstatic <K,V> Map<K, V> mutableMap(K k1, V v1, K k2, V v2, K k3, V v3) Convenience method for the inline creation of a map with valuesstatic <K,V> Map<K, V> mutableMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Convenience method for the inline creation of a map with valuesstatic <E> Set<E>mutableSet.static <E> Set<E>mutableSet(E element) mutableSet.static <E> Set<E>mutableSet(E... elements) mutableSet.static <E> Set<E>mutableSet(Iterable<? extends E> elements) Creates a mutableSetinstance containing the given elements.static <E> Set<E>mutableSet(Collection<? extends E> elements) Creates a mutableSetinstance containing the given elements.static <E> Set<E>mutableSet(Iterator<? extends E> elements) Creates a mutableSetinstance containing the given elements.static <E> Set<E>mutableSet(Stream<? extends E> elements) Creates a mutableSetinstance containing the given elements.static <E> SortedSet<E>mutableSortedSet.static <E> SortedSet<E>mutableSortedSet(E element) mutableSortedSet.static <E> SortedSet<E>mutableSortedSet(E... elements) mutableSortedSet.static <E> SortedSet<E>mutableSortedSet(Iterable<? extends E> elements) Creates a mutableSortedSetinstance containing the given elements.static <E> SortedSet<E>mutableSortedSet(Iterator<? extends E> elements) Creates a mutableSortedSetinstance containing the given elements.static <E> SortedSet<E>mutableSortedSet(Stream<? extends E> elements) Creates a mutableSortedSetinstance containing the given elements.
-
Constructor Details
-
CollectionLiterals
public CollectionLiterals()
-
-
Method Details
-
mutableList
mutableList.
- Type Parameters:
E- a E class- Returns:
- a newly created empty
ArrayList
-
mutableList
Creates a mutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added- Returns:
- the mutable
Listwith the given elements
-
mutableList
Creates a mutableListinstance containing the given element- Type Parameters:
E- a E class- Parameters:
element- to be added- Returns:
- the mutable
Listwith the given element
-
mutableList
Creates a mutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Listwith the given elements
-
mutableList
Creates a mutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Listwith the given elements
-
mutableList
Creates a mutableListinstance containing the given elements. Caution: The stream will be consumed by this operation- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null an empty mutableListwill be returned- Returns:
- the mutable
Listwith the given elements
-
mutableList
Creates a mutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Listwith the given elements
-
immutableList
Creates an immutableListinstance. Convenience method forCollections.emptyList()- Type Parameters:
E- a E class- Returns:
- the immutable
Listwithout any element
-
immutableList
Creates an immutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Listwith the given elements
-
immutableList
Creates an immutableListinstance containing the given element.- Type Parameters:
E- a E class- Parameters:
element- to be wrapped, must not be null- Returns:
- the immutable
Listwith the given elements
-
immutableList
Creates an immutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Listwith the given elements
-
immutableList
Creates an immutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Listwith the given elements. It implicitly creates a copy
-
immutableList
Creates an immutableListinstance containing the given elements. Caution: The stream will be consumed by this operation- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Listwith the given elements
-
immutableList
Creates an immutableListinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Listwith the given elements
-
mutableSet
mutableSet.
- Type Parameters:
E- a E class- Returns:
- a newly created empty
HashSet
-
mutableSet
mutableSet.
- Type Parameters:
E- a E class- Parameters:
element- to be added. If it isnullit will not be added- Returns:
- a newly created empty
HashSetwith the given elements
-
mutableSet
mutableSet.
- Type Parameters:
E- a E class- Parameters:
elements- to be added- Returns:
- a newly created empty
HashSetwith the given elements
-
mutableSet
Creates a mutableSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Setwith the given elements
-
mutableSet
Creates a mutableSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Setwith the given elements
-
mutableSet
Creates a mutableSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Setwith the given elements
-
mutableSet
Creates a mutableSetinstance containing the given elements. Caution: The stream will be consumed by this operation -
immutableSet
immutableSet.
- Type Parameters:
E- a E class- Returns:
- a newly created empty
HashSetConvenience method forCollections.emptySet()
-
immutableSet
Creates an immutableSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
element- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
immutableSet
Creates an immutableSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
immutableSet
Creates an immutableSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped- Returns:
- the immutable
Setwith the given elements
-
immutableSet
Creates an immutableSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
immutableSet
Creates an immutableSetinstance containing the given elements. Caution: The stream will be consumed by this operation- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
mutableSortedSet
mutableSortedSet.
- Type Parameters:
E- a E class- Returns:
- a newly created empty
TreeSet
-
mutableSortedSet
mutableSortedSet.
-
mutableSortedSet
mutableSortedSet.
- Type Parameters:
E- a E class- Parameters:
elements- to be added- Returns:
- a newly created empty
TreeSetwith the given elements
-
mutableSortedSet
Creates a mutableSortedSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
TreeSetwith the given elements
-
mutableSortedSet
Creates a mutableSortedSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Setwith the given elements
-
mutableSortedSet
Creates a mutableSortedSetinstance containing the given elements. Caution: The stream will be consumed by this operation- Type Parameters:
E- a E class- Parameters:
elements- to be added. If it is null and empty mutable list will be returned- Returns:
- the mutable
Setwith the given elements
-
immutableSortedSet
immutableSortedSet.
- Type Parameters:
E- a E class- Returns:
- a newly created empty
SortedSetConvenience method forCollections.emptySortedSet()
-
immutableSortedSet
Creates an immutableSortedSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
element- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
immutableSortedSet
Creates an immutableSortedSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
immutableSortedSet
Creates an immutableSortedSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
immutableSortedSet
Creates an immutableSortedSetinstance containing the given elements.- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
immutableSortedSet
Creates an immutableSortedSetinstance containing the given elements. Caution: The stream will be consumed by this operation- Type Parameters:
E- a E class- Parameters:
elements- to be wrapped, must not be null- Returns:
- the immutable
Setwith the given elements
-
mutableMap
mutableMap.
- Type Parameters:
K- a K classV- a V class- Returns:
- an empty mutable Map
-
mutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k- key to be addedv- value to be added- Returns:
- a mutable Map with the given elements
-
mutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k1- key to be addedv1- value to be addedk2- key to be addedv2- value to be added- Returns:
- a mutable Map with the given elements
-
mutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k1- key to be addedv1- value to be addedk2- key to be addedv2- value to be addedk3- key to be addedv3- value to be added- Returns:
- a mutable Map with the given elements
-
mutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k1- key to be addedv1- value to be addedk2- key to be addedv2- value to be addedk3- key to be addedv3- value to be addedk4- key to be addedv4- value to be added- Returns:
- a mutable Map with the given elements
-
immutableMap
immutableMap.
- Type Parameters:
K- a K classV- a V class- Returns:
- an empty mutable Map
-
immutableMap
Shorthand toCollections.unmodifiableMap(Map)- Type Parameters:
K- a K classV- a V class- Parameters:
source- aMapobject- Returns:
- an immutable Map with the given elements
-
immutableMap
Copies the entries of the given map stream into a new map which is then returned as an unmodifiable map.- Type Parameters:
K- key typeV- value type- Parameters:
elements- to be copied- Returns:
- unmodifiable map with entries form the given stream
-
immutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k- key to be addedv- value to be added- Returns:
- an immutable Map with the given elements
-
immutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k1- key to be addedv1- value to be addedk2- key to be addedv2- value to be added- Returns:
- an immutable Map with the given elements
-
immutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k1- key to be addedv1- value to be addedk2- key to be addedv2- value to be addedk3- key to be addedv3- value to be added- Returns:
- an immutable Map with the given elements
-
immutableMap
Convenience method for the inline creation of a map with values- Type Parameters:
K- a K classV- a V class- Parameters:
k1- key to be addedv1- value to be addedk2- key to be addedv2- value to be addedk3- key to be addedv3- value to be addedk4- key to be addedv4- value to be added- Returns:
- an immutable Map with the given elements
-