Package org.eclipse.xtext.xbase.lib
Class CollectionExtensions
- java.lang.Object
-
- org.eclipse.xtext.xbase.lib.CollectionExtensions
-
@GwtCompatible public class CollectionExtensions extends java.lang.Object
This is an extension library forcollections
.
-
-
Constructor Summary
Constructors Constructor Description CollectionExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> boolean
addAll(java.util.Collection<? super T> collection, T... elements)
Adds all of the specified elements to the specified collection.static <T> boolean
addAll(java.util.Collection<T> collection, java.lang.Iterable<? extends T> elements)
Adds all of the specified elements to the specified collection.static <T> java.util.List<T>
immutableCopy(java.util.List<? extends T> list)
Returns an immutable copy of the specifiedlist
.static <K,V>
java.util.Map<K,V>immutableCopy(java.util.Map<? extends K,? extends V> map)
Returns an immutable copy of the specifiedmap
.static <T> java.util.Set<T>
immutableCopy(java.util.Set<? extends T> set)
Returns an immutable copy of the specifiedset
.static <K,V>
java.util.SortedMap<K,V>immutableCopy(java.util.SortedMap<K,? extends V> map)
Returns an immutable copy of the specified sortedmap
.static <T> java.util.SortedSet<T>
immutableCopy(java.util.SortedSet<T> set)
Returns an immutable copy of the specified sortedset
.static <E> boolean
operator_add(java.util.Collection<? super E> collection, E value)
The operator mapping from+=
toCollection.add(Object)
.static <E> boolean
operator_add(java.util.Collection<E> collection, java.lang.Iterable<? extends E> newElements)
The operator mapping from+=
toaddAll(Collection, Iterable)
.static <E> boolean
operator_remove(java.util.Collection<? super E> collection, E value)
The operator mapping from-=
toCollection.remove(Object)
.static <E> boolean
operator_remove(java.util.Collection<E> collection, java.util.Collection<? extends E> newElements)
The operator mapping from-=
toremoveAll(Collection, Collection)
.static <T> boolean
removeAll(java.util.Collection<? super T> collection, T... elements)
Removes all of the specified elements from the specified collection.static <T> boolean
removeAll(java.util.Collection<T> collection, java.lang.Iterable<? extends T> elements)
Removes all of the specified elements from the specified collection.static <T> boolean
removeAll(java.util.Collection<T> collection, java.util.Collection<? extends T> elements)
Removes all of the specified elements from the specified collection.static <T> java.util.Collection<T>
unmodifiableView(java.util.Collection<? extends T> collection)
Returns an unmodifiable view of the specifiedcollection
.static <T> java.util.List<T>
unmodifiableView(java.util.List<? extends T> list)
Returns an unmodifiable view of the specifiedlist
.static <K,V>
java.util.Map<K,V>unmodifiableView(java.util.Map<? extends K,? extends V> map)
Returns an unmodifiable view of the specifiedmap
.static <T> java.util.Set<T>
unmodifiableView(java.util.Set<? extends T> set)
Returns an unmodifiable view of the specifiedset
.static <K,V>
java.util.SortedMap<K,V>unmodifiableView(java.util.SortedMap<K,? extends V> map)
Returns an unmodifiable view of the specified sortedmap
.static <T> java.util.SortedSet<T>
unmodifiableView(java.util.SortedSet<T> set)
Returns an unmodifiable view of the specified sortedset
.
-
-
-
Method Detail
-
operator_add
public static <E> boolean operator_add(java.util.Collection<? super E> collection, E value)
The operator mapping from+=
toCollection.add(Object)
. Returnstrue
if the collection changed due to this operation.- Parameters:
collection
- the to-be-changed collection. May not benull
.value
- the value that should be added to the collection.- Returns:
true
if the collection changed due to this operation.- See Also:
Collection.add(Object)
-
operator_add
public static <E> boolean operator_add(java.util.Collection<E> collection, java.lang.Iterable<? extends E> newElements)
The operator mapping from+=
toaddAll(Collection, Iterable)
. Returnstrue
if the collection changed due to this operation.- Parameters:
collection
- the to-be-changed collection. May not benull
.newElements
- elements to be inserted into the collection. May not benull
but may containnull
elements if the target collection supportsnull
elements.- Returns:
true
if the collection changed due to this operation.- See Also:
addAll(Collection, Iterable)
-
operator_remove
public static <E> boolean operator_remove(java.util.Collection<? super E> collection, E value)
The operator mapping from-=
toCollection.remove(Object)
. Returnstrue
if the collection changed due to this operation.- Parameters:
collection
- the to-be-changed collection. May not benull
.value
- the value that should be removed from the collection.- Returns:
true
if the collection changed due to this operation.- Since:
- 2.4
- See Also:
Collection.remove(Object)
-
operator_remove
public static <E> boolean operator_remove(java.util.Collection<E> collection, java.util.Collection<? extends E> newElements)
The operator mapping from-=
toremoveAll(Collection, Collection)
. Returnstrue
if the collection changed due to this operation.- Parameters:
collection
- the to-be-changed collection. May not benull
.newElements
- elements to be removed from the collection. May not benull
but may containnull
elements if the target collection supportsnull
elements.- Returns:
true
if the collection changed due to this operation.- Since:
- 2.4
- See Also:
removeAll(Collection, Collection)
-
unmodifiableView
public static <T> java.util.List<T> unmodifiableView(java.util.List<? extends T> list)
Returns an unmodifiable view of the specifiedlist
.- Parameters:
list
- the list for which an unmodifiable view is to be returned. May not benull
.- Returns:
- an unmodifiable view of the specified list.
- See Also:
Collections.unmodifiableList(List)
-
unmodifiableView
public static <T> java.util.Collection<T> unmodifiableView(java.util.Collection<? extends T> collection)
Returns an unmodifiable view of the specifiedcollection
.- Parameters:
collection
- the collection for which an unmodifiable view is to be returned. May not benull
.- Returns:
- an unmodifiable view of the specified collection.
- See Also:
Collections.unmodifiableCollection(Collection)
-
unmodifiableView
public static <T> java.util.Set<T> unmodifiableView(java.util.Set<? extends T> set)
Returns an unmodifiable view of the specifiedset
.- Parameters:
set
- the set for which an unmodifiable view is to be returned. May not benull
.- Returns:
- an unmodifiable view of the specified set.
- See Also:
Collections.unmodifiableSet(Set)
-
unmodifiableView
public static <T> java.util.SortedSet<T> unmodifiableView(java.util.SortedSet<T> set)
Returns an unmodifiable view of the specified sortedset
.- Parameters:
set
- the sorted set for which an unmodifiable view is to be returned. May not benull
.- Returns:
- an unmodifiable view of the specified sorted set.
- See Also:
Collections.unmodifiableSortedSet(SortedSet)
-
unmodifiableView
public static <K,V> java.util.Map<K,V> unmodifiableView(java.util.Map<? extends K,? extends V> map)
Returns an unmodifiable view of the specifiedmap
.- Parameters:
map
- the map for which an unmodifiable view is to be returned. May not benull
.- Returns:
- an unmodifiable view of the specified map.
- See Also:
Collections.unmodifiableMap(Map)
-
unmodifiableView
public static <K,V> java.util.SortedMap<K,V> unmodifiableView(java.util.SortedMap<K,? extends V> map)
Returns an unmodifiable view of the specified sortedmap
.- Parameters:
map
- the sorted map for which an unmodifiable view is to be returned. May not benull
.- Returns:
- an unmodifiable view of the specified sorted map.
- See Also:
Collections.unmodifiableSortedMap(SortedMap)
-
immutableCopy
public static <T> java.util.List<T> immutableCopy(java.util.List<? extends T> list)
Returns an immutable copy of the specifiedlist
.- Parameters:
list
- the list for which an immutable copy should be created. May not benull
.- Returns:
- an immutable copy of the specified list.
-
immutableCopy
public static <T> java.util.Set<T> immutableCopy(java.util.Set<? extends T> set)
Returns an immutable copy of the specifiedset
.- Parameters:
set
- the set for which an immutable copy should be created. May not benull
.- Returns:
- an immutable copy of the specified set.
-
immutableCopy
public static <T> java.util.SortedSet<T> immutableCopy(java.util.SortedSet<T> set)
Returns an immutable copy of the specified sortedset
.- Parameters:
set
- the sorted set for which an immutable copy should be created. May not benull
.- Returns:
- an immutable copy of the specified sorted set.
-
immutableCopy
public static <K,V> java.util.Map<K,V> immutableCopy(java.util.Map<? extends K,? extends V> map)
Returns an immutable copy of the specifiedmap
.- Parameters:
map
- the map for which an immutable copy should be created. May not benull
.- Returns:
- an immutable copy of the specified map.
-
immutableCopy
public static <K,V> java.util.SortedMap<K,V> immutableCopy(java.util.SortedMap<K,? extends V> map)
Returns an immutable copy of the specified sortedmap
.- Parameters:
map
- the sorted map for which an immutable copy should be created. May not benull
.- Returns:
- an immutable copy of the specified sorted map.
-
addAll
@SafeVarargs public static <T> boolean addAll(java.util.Collection<? super T> collection, T... elements)
Adds all of the specified elements to the specified collection.- Parameters:
collection
- the collection into which theelements
are to be inserted. May not benull
.elements
- the elements to insert into thecollection
. May not benull
but may containnull
entries if thecollection
allows that.- Returns:
true
if the collection changed as a result of the call
-
addAll
public static <T> boolean addAll(java.util.Collection<T> collection, java.lang.Iterable<? extends T> elements)
Adds all of the specified elements to the specified collection.- Parameters:
collection
- the collection into which theelements
are to be inserted. May not benull
.elements
- the elements to insert into thecollection
. May not benull
but may containnull
entries if thecollection
allows that.- Returns:
true
if the collection changed as a result of the call
-
removeAll
@SafeVarargs public static <T> boolean removeAll(java.util.Collection<? super T> collection, T... elements)
Removes all of the specified elements from the specified collection.- Parameters:
collection
- the collection from which theelements
are to be removed. May not benull
.elements
- the elements be remove from thecollection
. May not benull
but may containnull
entries if thecollection
allows that.- Returns:
true
if the collection changed as a result of the call- Since:
- 2.4
-
removeAll
public static <T> boolean removeAll(java.util.Collection<T> collection, java.util.Collection<? extends T> elements)
Removes all of the specified elements from the specified collection.- Parameters:
collection
- the collection from which theelements
are to be removed. May not benull
.elements
- the elements to remove from thecollection
. May not benull
but may containnull
entries if thecollection
allows that.- Returns:
true
if the collection changed as a result of the call- Since:
- 2.4
-
removeAll
public static <T> boolean removeAll(java.util.Collection<T> collection, java.lang.Iterable<? extends T> elements)
Removes all of the specified elements from the specified collection.- Parameters:
collection
- the collection from which theelements
are to be removed. May not benull
.elements
- the elements to remove from thecollection
. May not benull
but may containnull
entries if thecollection
allows that.- Returns:
true
if the collection changed as a result of the call- Since:
- 2.4
-
-