Top Description Constructors Methods
org.eclipse.xtext.xbase.lib

public Class CollectionLiterals

extends Object
Class Inheritance
Annotations
@GwtCompatible
Imports
java.util.ArrayList, .Arrays, .Collections, .Comparator, .HashMap, .HashSet, .LinkedHashMap, .LinkedHashSet, .LinkedList, .List, .Map, .Set, .TreeMap, .TreeSet, com.google.common.annotations.GwtCompatible, com.google.common.collect.ImmutableList, .ImmutableMap, .ImmutableSet, .Lists, .Sets, com.google.common.primitives.Ints

This is an extension library for collections.
Author
Sebastian Zarnekow - Initial contribution and API

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static int
capacity(int initialSize)

public static <T> List<T>

Returns:

an empty, immutable list.
emptyList
()

Returns the empty, immutable list.

public static <K, V> Map<K, V>

Returns:

an empty, immutable map.
emptyMap
()

Returns the empty, immutable map.

public static <T> Set<T>

Returns:

an empty, immutable set.
emptySet
()

Returns the empty, immutable set.

public static <T> ArrayList<T>

Returns:

a new ArrayList
newArrayList
()

Creates an empty mutable ArrayList instance.

public static <T> ArrayList<T>

Returns:

a new ArrayList containing those elements
newArrayList
(T...
the initial elements that the list should contain, in order. May not be null but may contain null values.
initial
)

Creates a mutable ArrayList instance containing the given initial elements.

public static <K, V> HashMap<K, V>

Returns:

a new HashMap
newHashMap
()

Creates an empty mutable HashMap instance.

public static <K, V> HashMap<K, V>

Returns:

a new HashMap containing those elements
newHashMap
(Pair<? extends K, ? extends V>...
the entries that should be contained in the map. May not be null but may contain null keys or values.
initial
)

Creates a mutable HashMap instance containing the given initial entries.

public static <T> HashSet<T>

Returns:

a new HashSet
newHashSet
()

Creates an empty mutable HashSet instance.

public static <T> HashSet<T>

Returns:

a new HashSet containing those elements
newHashSet
(T...
the initial elements that the set should contain, in order. May not be null but may contain null values.
initial
)

Creates a mutable HashSet instance containing the given initial elements.

public static <T> List<T>

Returns:

an immutable list containing the given elements.
newImmutableList
(T...
the elements that should be contained in the list. May not be null or contain any null values.
elements
)

Returns an immutable list containing the given elements, in order.

public static <K, V> Map<K, V>

Returns:

an immutable map containing the given entries.
newImmutableMap
(Pair<? extends K, ? extends V>...
the entries that should be contained in the map. May not be null and may not contain any null keys or values.
entries
)

Returns an immutable map containing the given entries.

public static <T> Set<T>

Returns:

an immutable set containing the given elements.
newImmutableSet
(T...
the elements that should be contained in the set. May not be null or contain any null values.
elements
)

Returns an immutable set containing the given elements.

public static <K, V> LinkedHashMap<K, V>

Returns:

a new LinkedHashMap
newLinkedHashMap
()

Creates an empty mutable LinkedHashMap instance.

public static <K, V> LinkedHashMap<K, V>

Returns:

a new LinkedHashMap containing those elements
newLinkedHashMap
(Pair<? extends K, ? extends V>...
the entries that should be contained in the map. May not be null but may contain null keys or values.
initial
)

Creates a mutable LinkedHashMap instance containing the given initial entries.

public static <T> LinkedHashSet<T>

Returns:

a new LinkedHashSet
newLinkedHashSet
()

Creates an empty mutable LinkedHashSet instance.

public static <T> LinkedHashSet<T>

Returns:

a new LinkedHashSet containing those elements
newLinkedHashSet
(T...
the initial elements that the set should contain, in order. May not be null but may contain null values.
initial
)

Creates a mutable LinkedHashSet instance containing the given initial elements.

public static <T> LinkedList<T>

Returns:

a new LinkedList
newLinkedList
()

Creates an empty mutable LinkedList instance.

public static <T> LinkedList<T>

Returns:

a new LinkedList containing those elements
newLinkedList
(T...
the initial elements that the list should contain, in order. May not be null but may contain null values.
initial
)

Creates a mutable LinkedList instance containing the given initial elements.

public static <K, V> TreeMap<K, V>

Returns:

a new TreeMap
newTreeMap
(Comparator<? super K>
the comparator that should be used. May be null which indicates that the natural ordering of the keys should be used.
comparator
)

Creates an empty mutable TreeMap instance.

public static <K, V> TreeMap<K, V>

Returns:

a new TreeMap containing those elements
newTreeMap
(Comparator<? super K>
the comparator that should be used. May be null which indicates that the natural ordering of the keys should be used.
comparator
,
Pair<? extends K, ? extends V>...
the entries that should be contained in the map. May not be null but may contain null keys or values.
initial
)

Creates a mutable TreeMap instance containing the given initial entries.

public static <T> TreeSet<T>

Returns:

a new TreeSet
newTreeSet
(Comparator<? super T>
the comparator that should be used. May be null which indicates that the natural ordering of the items should be used.
comparator
)

Creates an empty mutable TreeSet instance.

public static <T> TreeSet<T>

Returns:

a new TreeSet containing those elements
newTreeSet
(Comparator<? super T>
the comparator that should be used. May be null which indicates that the natural ordering of the items should be used.
comparator
,
T...
the initial elements that the set should contain, in order. May not be null but may contain null values.
initial
)

Creates a mutable TreeSet instance containing the given initial elements.

private static <K, V> void
putAll(Map<K, V> result, Pair<? extends K, ? extends V>... entries)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CollectionLiteralsback to summary
public CollectionLiterals()

Method Detail

capacityback to summary
private static int capacity(int initialSize)
emptyListback to summary
public static <T> List<T> emptyList()

Returns the empty, immutable list.

Returns:List<T>

an empty, immutable list.

Annotations
@Pure
See Also
Collections#emptyList()
emptyMapback to summary
public static <K, V> Map<K, V> emptyMap()

Returns the empty, immutable map.

Returns:Map<K, V>

an empty, immutable map.

Annotations
@Pure
See Also
Collections#emptyMap()
emptySetback to summary
public static <T> Set<T> emptySet()

Returns the empty, immutable set.

Returns:Set<T>

an empty, immutable set.

Annotations
@Pure
See Also
Collections#emptySet()
newArrayListback to summary
public static <T> ArrayList<T> newArrayList()

Creates an empty mutable ArrayList instance.

Returns:ArrayList<T>

a new ArrayList

Annotations
@Pure
Since
2.13
newArrayListback to summary
public static <T> ArrayList<T> newArrayList(T... initial)

Creates a mutable ArrayList instance containing the given initial elements.

Parameters
initial:T[]

the initial elements that the list should contain, in order. May not be null but may contain null values.

Returns:ArrayList<T>

a new ArrayList containing those elements

Annotations
@SafeVarargs
@Pure
newHashMapback to summary
public static <K, V> HashMap<K, V> newHashMap()

Creates an empty mutable HashMap instance.

Returns:HashMap<K, V>

a new HashMap

Annotations
@Pure
Since
2.13
newHashMapback to summary
public static <K, V> HashMap<K, V> newHashMap(Pair<? extends K, ? extends V>... initial)

Creates a mutable HashMap instance containing the given initial entries. Repeated occurrences of a keys will cause an IllegalArgumentException.

Parameters
initial:Pair<? extends K, ? extends V>[]

the entries that should be contained in the map. May not be null but may contain null keys or values.

Returns:HashMap<K, V>

a new HashMap containing those elements

Annotations
@SafeVarargs
@Pure
Exceptions
IllegalArgumentException:
if duplicate keys are contained the initial entries.
newHashSetback to summary
public static <T> HashSet<T> newHashSet()

Creates an empty mutable HashSet instance.

Returns:HashSet<T>

a new HashSet

Annotations
@Pure
Since
2.13
newHashSetback to summary
public static <T> HashSet<T> newHashSet(T... initial)

Creates a mutable HashSet instance containing the given initial elements.

Parameters
initial:T[]

the initial elements that the set should contain, in order. May not be null but may contain null values.

Returns:HashSet<T>

a new HashSet containing those elements

Annotations
@SafeVarargs
@Pure
newImmutableListback to summary
public static <T> List<T> newImmutableList(T... elements)

Returns an immutable list containing the given elements, in order.

Parameters
elements:T[]

the elements that should be contained in the list. May not be null or contain any null values.

Returns:List<T>

an immutable list containing the given elements.

Annotations
@Pure
@SafeVarargs
Exceptions
NullPointerException:
if elements or any of items in elements is null
newImmutableMapback to summary
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 an IllegalArgumentException.

Parameters
entries:Pair<? extends K, ? extends V>[]

the entries that should be contained in the map. May not be null and may not contain any null keys or values.

Returns:Map<K, V>

an immutable map containing the given entries.

Annotations
@Pure
@SafeVarargs
Exceptions
NullPointerException:
if entries or any key or value in entries is null
IllegalArgumentException:
if duplicate keys are contained in entries.
newImmutableSetback to summary
public static <T> Set<T> newImmutableSet(T... elements)

Returns an immutable set containing the given elements. Repeated occurrences of an element (according to Object#equals) after the first are ignored

Parameters
elements:T[]

the elements that should be contained in the set. May not be null or contain any null values.

Returns:Set<T>

an immutable set containing the given elements.

Annotations
@Pure
@SafeVarargs
Exceptions
NullPointerException:
if elements or any of items in elements is null
newLinkedHashMapback to summary
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap()

Creates an empty mutable LinkedHashMap instance.

Returns:LinkedHashMap<K, V>

a new LinkedHashMap

Annotations
@Pure
Since
2.13
newLinkedHashMapback to summary
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(Pair<? extends K, ? extends V>... initial)

Creates a mutable LinkedHashMap instance containing the given initial entries. Repeated occurrences of a keys will cause an IllegalArgumentException.

Parameters
initial:Pair<? extends K, ? extends V>[]

the entries that should be contained in the map. May not be null but may contain null keys or values.

Returns:LinkedHashMap<K, V>

a new LinkedHashMap containing those elements

Annotations
@SafeVarargs
@Pure
Exceptions
IllegalArgumentException:
if duplicate keys are contained the initial entries.
newLinkedHashSetback to summary
public static <T> LinkedHashSet<T> newLinkedHashSet()

Creates an empty mutable LinkedHashSet instance.

Returns:LinkedHashSet<T>

a new LinkedHashSet

Annotations
@Pure
Since
2.13
newLinkedHashSetback to summary
public static <T> LinkedHashSet<T> newLinkedHashSet(T... initial)

Creates a mutable LinkedHashSet instance containing the given initial elements.

Parameters
initial:T[]

the initial elements that the set should contain, in order. May not be null but may contain null values.

Returns:LinkedHashSet<T>

a new LinkedHashSet containing those elements

Annotations
@SafeVarargs
@Pure
newLinkedListback to summary
public static <T> LinkedList<T> newLinkedList()

Creates an empty mutable LinkedList instance.

Returns:LinkedList<T>

a new LinkedList

Annotations
@Pure
Since
2.13
newLinkedListback to summary
public static <T> LinkedList<T> newLinkedList(T... initial)

Creates a mutable LinkedList instance containing the given initial elements.

Parameters
initial:T[]

the initial elements that the list should contain, in order. May not be null but may contain null values.

Returns:LinkedList<T>

a new LinkedList containing those elements

Annotations
@SafeVarargs
@Pure
newTreeMapback to summary
public static <K, V> TreeMap<K, V> newTreeMap(Comparator<? super K> comparator)

Creates an empty mutable TreeMap instance.

Parameters
comparator:Comparator<? super K>

the comparator that should be used. May be null which indicates that the natural ordering of the keys should be used.

Returns:TreeMap<K, V>

a new TreeMap

Annotations
@Pure
Since
2.13
newTreeMapback to summary
public static <K, V> TreeMap<K, V> newTreeMap(Comparator<? super K> comparator, Pair<? extends K, ? extends V>... initial)

Creates a mutable TreeMap instance containing the given initial entries. Repeated occurrences of a keys will cause an IllegalArgumentException.

Parameters
comparator:Comparator<? super K>

the comparator that should be used. May be null which indicates that the natural ordering of the keys should be used.

initial:Pair<? extends K, ? extends V>[]

the entries that should be contained in the map. May not be null but may contain null keys or values.

Returns:TreeMap<K, V>

a new TreeMap containing those elements

Annotations
@SafeVarargs
@Pure
Exceptions
IllegalArgumentException:
if duplicate keys are contained the initial entries.
newTreeSetback to summary
public static <T> TreeSet<T> newTreeSet(Comparator<? super T> comparator)

Creates an empty mutable TreeSet instance.

Parameters
comparator:Comparator<? super T>

the comparator that should be used. May be null which indicates that the natural ordering of the items should be used.

Returns:TreeSet<T>

a new TreeSet

Annotations
@Pure
Since
2.13
newTreeSetback to summary
public static <T> TreeSet<T> newTreeSet(Comparator<? super T> comparator, T... initial)

Creates a mutable TreeSet instance containing the given initial elements.

Parameters
comparator:Comparator<? super T>

the comparator that should be used. May be null which indicates that the natural ordering of the items should be used.

initial:T[]

the initial elements that the set should contain, in order. May not be null but may contain null values.

Returns:TreeSet<T>

a new TreeSet containing those elements

Annotations
@SafeVarargs
@Pure
putAllback to summary
private static <K, V> void putAll(Map<K, V> result, Pair<? extends K, ? extends V>... entries)
Annotations
@SafeVarargs