Package org.eclipse.xtext.xbase.lib
Class CollectionLiterals
java.lang.Object
org.eclipse.xtext.xbase.lib.CollectionLiterals
This is an extension library for
collections
.- Author:
- Sebastian Zarnekow - Initial contribution and API
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>
Returns the empty, immutable list.static <K,
V> Map<K, V> emptyMap()
Returns the empty, immutable map.static <T> Set<T>
emptySet()
Returns the empty, immutable set.static <T> ArrayList<T>
Creates an empty mutableArrayList
instance.static <T> ArrayList<T>
newArrayList
(T... initial) Creates a mutableArrayList
instance containing the given initial elements.static <K,
V> HashMap<K, V> Creates an empty mutableHashMap
instance.static <K,
V> HashMap<K, V> newHashMap
(Pair<? extends K, ? extends V>... initial) Creates a mutableHashMap
instance containing the given initial entries.static <T> HashSet<T>
Creates an empty mutableHashSet
instance.static <T> HashSet<T>
newHashSet
(T... initial) Creates a mutableHashSet
instance containing the given initial elements.static <T> List<T>
newImmutableList
(T... elements) Returns an immutable list containing the given elements, in order.static <K,
V> Map<K, V> newImmutableMap
(Pair<? extends K, ? extends V>... entries) Returns an immutable map containing the given entries.static <T> Set<T>
newImmutableSet
(T... elements) Returns an immutable set containing the given elements.static <K,
V> LinkedHashMap<K, V> Creates an empty mutableLinkedHashMap
instance.static <K,
V> LinkedHashMap<K, V> newLinkedHashMap
(Pair<? extends K, ? extends V>... initial) Creates a mutableLinkedHashMap
instance containing the given initial entries.static <T> LinkedHashSet<T>
Creates an empty mutableLinkedHashSet
instance.static <T> LinkedHashSet<T>
newLinkedHashSet
(T... initial) Creates a mutableLinkedHashSet
instance containing the given initial elements.static <T> LinkedList<T>
Creates an empty mutableLinkedList
instance.static <T> LinkedList<T>
newLinkedList
(T... initial) Creates a mutableLinkedList
instance containing the given initial elements.static <K,
V> TreeMap<K, V> newTreeMap
(Comparator<? super K> comparator) Creates an empty mutableTreeMap
instance.static <K,
V> TreeMap<K, V> newTreeMap
(Comparator<? super K> comparator, Pair<? extends K, ? extends V>... initial) Creates a mutableTreeMap
instance containing the given initial entries.static <T> TreeSet<T>
newTreeSet
(Comparator<? super T> comparator) Creates an empty mutableTreeSet
instance.static <T> TreeSet<T>
newTreeSet
(Comparator<? super T> comparator, T... initial) Creates a mutableTreeSet
instance containing the given initial elements.
-
Constructor Details
-
CollectionLiterals
public CollectionLiterals()
-
-
Method Details
-
emptyList
Returns the empty, immutable list.- Returns:
- an empty, immutable list.
- See Also:
-
emptySet
Returns the empty, immutable set.- Returns:
- an empty, immutable set.
- See Also:
-
emptyMap
Returns the empty, immutable map.- Returns:
- an empty, immutable map.
- See Also:
-
newImmutableList
Returns an immutable list containing the given elements, in order.- Parameters:
elements
- the elements that should be contained in the list. May not benull
or contain anynull
values.- Returns:
- an immutable list containing the given elements.
- Throws:
NullPointerException
- ifelements
or any of items inelements
isnull
-
newImmutableSet
Returns an immutable set containing the given elements. Repeated occurrences of an element (according toObject.equals(java.lang.Object)
) after the first are ignored- Parameters:
elements
- the elements that should be contained in the set. May not benull
or contain anynull
values.- Returns:
- an immutable set containing the given elements.
- Throws:
NullPointerException
- ifelements
or any of items inelements
isnull
-
newImmutableMap
@Pure @SafeVarargs public static <K,V> Map<K,V> newImmutableMap(Pair<? extends K, ? extends V>... entries) Returns an immutable map containing the given entries. Repeated occurrences of a keys will cause anIllegalArgumentException
.- Parameters:
entries
- the entries that should be contained in the map. May not benull
and may not contain anynull
keys or values.- Returns:
- an immutable map containing the given entries.
- Throws:
NullPointerException
- ifentries
or any key or value inentries
isnull
IllegalArgumentException
- if duplicate keys are contained inentries
.
-
newArrayList
Creates an empty mutableArrayList
instance.- Returns:
- a new
ArrayList
- Since:
- 2.13
-
newArrayList
Creates a mutableArrayList
instance containing the given initial elements.- Parameters:
initial
- the initial elements that the list should contain, in order. May not benull
but may containnull
values.- Returns:
- a new
ArrayList
containing those elements
-
newLinkedList
Creates an empty mutableLinkedList
instance.- Returns:
- a new
LinkedList
- Since:
- 2.13
-
newLinkedList
Creates a mutableLinkedList
instance containing the given initial elements.- Parameters:
initial
- the initial elements that the list should contain, in order. May not benull
but may containnull
values.- Returns:
- a new
LinkedList
containing those elements
-
newHashSet
Creates an empty mutableHashSet
instance.- Returns:
- a new
HashSet
- Since:
- 2.13
-
newHashSet
Creates a mutableHashSet
instance containing the given initial elements.- Parameters:
initial
- the initial elements that the set should contain, in order. May not benull
but may containnull
values.- Returns:
- a new
HashSet
containing those elements
-
newLinkedHashSet
Creates an empty mutableLinkedHashSet
instance.- Returns:
- a new
LinkedHashSet
- Since:
- 2.13
-
newLinkedHashSet
Creates a mutableLinkedHashSet
instance containing the given initial elements.- Parameters:
initial
- the initial elements that the set should contain, in order. May not benull
but may containnull
values.- Returns:
- a new
LinkedHashSet
containing those elements
-
newTreeSet
Creates an empty mutableTreeSet
instance.- Parameters:
comparator
- the comparator that should be used. May benull
which indicates that the natural ordering of the items should be used.- Returns:
- a new
TreeSet
- Since:
- 2.13
-
newTreeSet
@SafeVarargs @Pure public static <T> TreeSet<T> newTreeSet(Comparator<? super T> comparator, T... initial) Creates a mutableTreeSet
instance containing the given initial elements.- Parameters:
initial
- the initial elements that the set should contain, in order. May not benull
but may containnull
values.comparator
- the comparator that should be used. May benull
which indicates that the natural ordering of the items should be used.- Returns:
- a new
TreeSet
containing those elements
-
newHashMap
Creates an empty mutableHashMap
instance.- Returns:
- a new
HashMap
- Since:
- 2.13
-
newHashMap
@SafeVarargs @Pure public static <K,V> HashMap<K,V> newHashMap(Pair<? extends K, ? extends V>... initial) Creates a mutableHashMap
instance containing the given initial entries. Repeated occurrences of a keys will cause anIllegalArgumentException
.- Parameters:
initial
- the entries that should be contained in the map. May not benull
but may containnull
keys or values.- Returns:
- a new
HashMap
containing those elements - Throws:
IllegalArgumentException
- if duplicate keys are contained theinitial
entries.
-
newLinkedHashMap
Creates an empty mutableLinkedHashMap
instance.- Returns:
- a new
LinkedHashMap
- Since:
- 2.13
-
newLinkedHashMap
@SafeVarargs @Pure public static <K,V> LinkedHashMap<K,V> newLinkedHashMap(Pair<? extends K, ? extends V>... initial) Creates a mutableLinkedHashMap
instance containing the given initial entries. Repeated occurrences of a keys will cause anIllegalArgumentException
.- Parameters:
initial
- the entries that should be contained in the map. May not benull
but may containnull
keys or values.- Returns:
- a new
LinkedHashMap
containing those elements - Throws:
IllegalArgumentException
- if duplicate keys are contained theinitial
entries.
-
newTreeMap
Creates an empty mutableTreeMap
instance.- Parameters:
comparator
- the comparator that should be used. May benull
which indicates that the natural ordering of the keys should be used.- Returns:
- a new
TreeMap
- Since:
- 2.13
-
newTreeMap
@SafeVarargs @Pure public static <K,V> TreeMap<K,V> newTreeMap(Comparator<? super K> comparator, Pair<? extends K, ? extends V>... initial) Creates a mutableTreeMap
instance containing the given initial entries. Repeated occurrences of a keys will cause anIllegalArgumentException
.- Parameters:
initial
- the entries that should be contained in the map. May not benull
but may containnull
keys or values.comparator
- the comparator that should be used. May benull
which indicates that the natural ordering of the keys should be used.- Returns:
- a new
TreeMap
containing those elements - Throws:
IllegalArgumentException
- if duplicate keys are contained theinitial
entries.
-