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

public Class CollectionExtensions

extends Object
Class Inheritance
Annotations
@GwtCompatible
Imports
java.util.Arrays, .Collection, .Collections, .List, .Map, .Set, .SortedMap, .SortedSet, com.google.common.annotations.GwtCompatible, com.google.common.collect.ImmutableList, .ImmutableMap, .ImmutableSet, .ImmutableSortedMap, .ImmutableSortedSet, .Iterables

This is an extension library for collections.
Authors
Sven Efftinge - Initial contribution and API, Sebastian Zarnekow

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <T> boolean

Returns:

true if the collection changed as a result of the call
addAll
(Collection<? super T>
the collection into which the elements are to be inserted. May not be null.
collection
,
T...
the elements to insert into the collection. May not be null but may contain null entries if the collection allows that.
elements
)

Adds all of the specified elements to the specified collection.

public static <T> boolean

Returns:

true if the collection changed as a result of the call
addAll
(Collection<T>
the collection into which the elements are to be inserted. May not be null.
collection
,
Iterable<? extends T>
the elements to insert into the collection. May not be null but may contain null entries if the collection allows that.
elements
)

Adds all of the specified elements to the specified collection.

public static <T> List<T>

Returns:

an immutable copy of the specified list.
immutableCopy
(List<? extends T>
the list for which an immutable copy should be created. May not be null.
list
)

Returns an immutable copy of the specified list.

public static <T> Set<T>

Returns:

an immutable copy of the specified set.
immutableCopy
(Set<? extends T>
the set for which an immutable copy should be created. May not be null.
set
)

Returns an immutable copy of the specified set.

public static <T> SortedSet<T>

Returns:

an immutable copy of the specified sorted set.
immutableCopy
(SortedSet<T>
the sorted set for which an immutable copy should be created. May not be null.
set
)

Returns an immutable copy of the specified sorted set.

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

Returns:

an immutable copy of the specified map.
immutableCopy
(Map<? extends K, ? extends V>
the map for which an immutable copy should be created. May not be null.
map
)

Returns an immutable copy of the specified map.

public static <K, V> SortedMap<K, V>

Returns:

an immutable copy of the specified sorted map.
immutableCopy
(SortedMap<K, ? extends V>
the sorted map for which an immutable copy should be created. May not be null.
map
)

Returns an immutable copy of the specified sorted map.

public static <E> boolean

Returns:

true if the collection changed due to this operation.
operator_add
(Collection<? super E>
the to-be-changed collection. May not be null.
collection
,
E
the value that should be added to the collection.
value
)

The operator mapping from += to Collection#add(Object).

public static <E> boolean

Returns:

true if the collection changed due to this operation.
operator_add
(Collection<E>
the to-be-changed collection. May not be null.
collection
,
Iterable<? extends E>
elements to be inserted into the collection. May not be null but may contain null elements if the target collection supports null elements.
newElements
)

The operator mapping from += to addAll(Collection, Iterable).

public static <E> boolean

Returns:

true if the collection changed due to this operation.
operator_remove
(Collection<? super E>
the to-be-changed collection. May not be null.
collection
,
E
the value that should be removed from the collection.
value
)

The operator mapping from -= to Collection#remove(Object).

public static <E> boolean

Returns:

true if the collection changed due to this operation.
operator_remove
(Collection<E>
the to-be-changed collection. May not be null.
collection
,
Collection<? extends E>
elements to be removed from the collection. May not be null but may contain null elements if the target collection supports null elements.
newElements
)

The operator mapping from -= to removeAll(Collection, Collection).

public static <T> boolean

Returns:

true if the collection changed as a result of the call
removeAll
(Collection<? super T>
the collection from which the elements are to be removed. May not be null.
collection
,
T...
the elements be remove from the collection. May not be null but may contain null entries if the collection allows that.
elements
)

Removes all of the specified elements from the specified collection.

public static <T> boolean

Returns:

true if the collection changed as a result of the call
removeAll
(Collection<T>
the collection from which the elements are to be removed. May not be null.
collection
,
Collection<? extends T>
the elements to remove from the collection. May not be null but may contain null entries if the collection allows that.
elements
)

Removes all of the specified elements from the specified collection.

public static <T> boolean

Returns:

true if the collection changed as a result of the call
removeAll
(Collection<T>
the collection from which the elements are to be removed. May not be null.
collection
,
Iterable<? extends T>
the elements to remove from the collection. May not be null but may contain null entries if the collection allows that.
elements
)

Removes all of the specified elements from the specified collection.

public static <T> List<T>

Returns:

an unmodifiable view of the specified list.
unmodifiableView
(List<? extends T>
the list for which an unmodifiable view is to be returned. May not be null.
list
)

Returns an unmodifiable view of the specified list.

public static <T> Collection<T>

Returns:

an unmodifiable view of the specified collection.
unmodifiableView
(Collection<? extends T>
the collection for which an unmodifiable view is to be returned. May not be null.
collection
)

Returns an unmodifiable view of the specified collection.

public static <T> Set<T>

Returns:

an unmodifiable view of the specified set.
unmodifiableView
(Set<? extends T>
the set for which an unmodifiable view is to be returned. May not be null.
set
)

Returns an unmodifiable view of the specified set.

public static <T> SortedSet<T>

Returns:

an unmodifiable view of the specified sorted set.
unmodifiableView
(SortedSet<T>
the sorted set for which an unmodifiable view is to be returned. May not be null.
set
)

Returns an unmodifiable view of the specified sorted set.

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

Returns:

an unmodifiable view of the specified map.
unmodifiableView
(Map<? extends K, ? extends V>
the map for which an unmodifiable view is to be returned. May not be null.
map
)

Returns an unmodifiable view of the specified map.

public static <K, V> SortedMap<K, V>

Returns:

an unmodifiable view of the specified sorted map.
unmodifiableView
(SortedMap<K, ? extends V>
the sorted map for which an unmodifiable view is to be returned. May not be null.
map
)

Returns an unmodifiable view of the specified sorted map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CollectionExtensionsback to summary
public CollectionExtensions()

Method Detail

addAllback to summary
public static <T> boolean addAll(Collection<? super T> collection, T... elements)

Adds all of the specified elements to the specified collection.

Parameters
collection:Collection<? super T>

the collection into which the elements are to be inserted. May not be null.

elements:T[]

the elements to insert into the collection. May not be null but may contain null entries if the collection allows that.

Returns:boolean

true if the collection changed as a result of the call

Annotations
@SafeVarargs
addAllback to summary
public static <T> boolean addAll(Collection<T> collection, Iterable<? extends T> elements)

Adds all of the specified elements to the specified collection.

Parameters
collection:Collection<T>

the collection into which the elements are to be inserted. May not be null.

elements:Iterable<? extends T>

the elements to insert into the collection. May not be null but may contain null entries if the collection allows that.

Returns:boolean

true if the collection changed as a result of the call

Annotations
@Inline:$3.$4addAll($1, $2)
imported:Iterables
immutableCopyback to summary
public static <T> List<T> immutableCopy(List<? extends T> list)

Returns an immutable copy of the specified list.

Parameters
list:List<? extends T>

the list for which an immutable copy should be created. May not be null.

Returns:List<T>

an immutable copy of the specified list.

Annotations
@Inline:$2.$3copyOf($1)
imported:ImmutableList
immutableCopyback to summary
public static <T> Set<T> immutableCopy(Set<? extends T> set)

Returns an immutable copy of the specified set.

Parameters
set:Set<? extends T>

the set for which an immutable copy should be created. May not be null.

Returns:Set<T>

an immutable copy of the specified set.

Annotations
@Inline:$2.$3copyOf($1)
imported:ImmutableSet
immutableCopyback to summary
public static <T> SortedSet<T> immutableCopy(SortedSet<T> set)

Returns an immutable copy of the specified sorted set.

Parameters
set:SortedSet<T>

the sorted set for which an immutable copy should be created. May not be null.

Returns:SortedSet<T>

an immutable copy of the specified sorted set.

Annotations
@Inline:$2.$3copyOfSorted($1)
imported:ImmutableSortedSet
immutableCopyback to summary
public static <K, V> Map<K, V> immutableCopy(Map<? extends K, ? extends V> map)

Returns an immutable copy of the specified map.

Parameters
map:Map<? extends K, ? extends V>

the map for which an immutable copy should be created. May not be null.

Returns:Map<K, V>

an immutable copy of the specified map.

Annotations
@Inline:$2.$3copyOf($1)
imported:ImmutableMap
immutableCopyback to summary
public static <K, V> SortedMap<K, V> immutableCopy(SortedMap<K, ? extends V> map)

Returns an immutable copy of the specified sorted map.

Parameters
map:SortedMap<K, ? extends V>

the sorted map for which an immutable copy should be created. May not be null.

Returns:SortedMap<K, V>

an immutable copy of the specified sorted map.

Annotations
@Inline:$2.$3copyOfSorted($1)
imported:ImmutableSortedMap
operator_addback to summary
public static <E> boolean operator_add(Collection<? super E> collection, E value)

The operator mapping from += to Collection#add(Object). Returns true if the collection changed due to this operation.

Parameters
collection:Collection<? super E>

the to-be-changed collection. May not be null.

value:E

the value that should be added to the collection.

Returns:boolean

true if the collection changed due to this operation.

Annotations
@Inline:$1.add($2)
See Also
Collection#add(Object)
operator_addback to summary
public static <E> boolean operator_add(Collection<E> collection, Iterable<? extends E> newElements)

The operator mapping from += to addAll(Collection, Iterable). Returns true if the collection changed due to this operation.

Parameters
collection:Collection<E>

the to-be-changed collection. May not be null.

newElements:Iterable<? extends E>

elements to be inserted into the collection. May not be null but may contain null elements if the target collection supports null elements.

Returns:boolean

true if the collection changed due to this operation.

Annotations
@Inline:$3.$4addAll($1, $2)
imported:Iterables
See Also
addAll(Collection, Iterable)
operator_removeback to summary
public static <E> boolean operator_remove(Collection<? super E> collection, E value)

The operator mapping from -= to Collection#remove(Object). Returns true if the collection changed due to this operation.

Parameters
collection:Collection<? super E>

the to-be-changed collection. May not be null.

value:E

the value that should be removed from the collection.

Returns:boolean

true if the collection changed due to this operation.

Annotations
@Inline:$1.remove($2)
Since
2.4
See Also
Collection#remove(Object)
operator_removeback to summary
public static <E> boolean operator_remove(Collection<E> collection, Collection<? extends E> newElements)

The operator mapping from -= to removeAll(Collection, Collection). Returns true if the collection changed due to this operation.

Parameters
collection:Collection<E>

the to-be-changed collection. May not be null.

newElements:Collection<? extends E>

elements to be removed from the collection. May not be null but may contain null elements if the target collection supports null elements.

Returns:boolean

true if the collection changed due to this operation.

Annotations
@Inline:$3.removeAll($1, $2)
imported:Iterables
Since
2.4
See Also
removeAll(Collection, Collection)
removeAllback to summary
public static <T> boolean removeAll(Collection<? super T> collection, T... elements)

Removes all of the specified elements from the specified collection.

Parameters
collection:Collection<? super T>

the collection from which the elements are to be removed. May not be null.

elements:T[]

the elements be remove from the collection. May not be null but may contain null entries if the collection allows that.

Returns:boolean

true if the collection changed as a result of the call

Annotations
@SafeVarargs
Since
2.4
removeAllback to summary
public static <T> boolean removeAll(Collection<T> collection, Collection<? extends T> elements)

Removes all of the specified elements from the specified collection.

Parameters
collection:Collection<T>

the collection from which the elements are to be removed. May not be null.

elements:Collection<? extends T>

the elements to remove from the collection. May not be null but may contain null entries if the collection allows that.

Returns:boolean

true if the collection changed as a result of the call

Annotations
@Inline:$3.$4removeAll($1, $2)
imported:Iterables
Since
2.4
removeAllback to summary
public static <T> boolean removeAll(Collection<T> collection, Iterable<? extends T> elements)

Removes all of the specified elements from the specified collection.

Parameters
collection:Collection<T>

the collection from which the elements are to be removed. May not be null.

elements:Iterable<? extends T>

the elements to remove from the collection. May not be null but may contain null entries if the collection allows that.

Returns:boolean

true if the collection changed as a result of the call

Since
2.4
unmodifiableViewback to summary
public static <T> List<T> unmodifiableView(List<? extends T> list)

Returns an unmodifiable view of the specified list.

Parameters
list:List<? extends T>

the list for which an unmodifiable view is to be returned. May not be null.

Returns:List<T>

an unmodifiable view of the specified list.

Annotations
@Inline:$2.$3unmodifiableList($1)
imported:Collections
See Also
Collections#unmodifiableList(List)
unmodifiableViewback to summary
public static <T> Collection<T> unmodifiableView(Collection<? extends T> collection)

Returns an unmodifiable view of the specified collection.

Parameters
collection:Collection<? extends T>

the collection for which an unmodifiable view is to be returned. May not be null.

Returns:Collection<T>

an unmodifiable view of the specified collection.

Annotations
@Inline:$2.$3unmodifiableCollection($1)
imported:Collections
See Also
Collections#unmodifiableCollection(Collection)
unmodifiableViewback to summary
public static <T> Set<T> unmodifiableView(Set<? extends T> set)

Returns an unmodifiable view of the specified set.

Parameters
set:Set<? extends T>

the set for which an unmodifiable view is to be returned. May not be null.

Returns:Set<T>

an unmodifiable view of the specified set.

Annotations
@Inline:$2.$3unmodifiableSet($1)
imported:Collections
See Also
Collections#unmodifiableSet(Set)
unmodifiableViewback to summary
public static <T> SortedSet<T> unmodifiableView(SortedSet<T> set)

Returns an unmodifiable view of the specified sorted set.

Parameters
set:SortedSet<T>

the sorted set for which an unmodifiable view is to be returned. May not be null.

Returns:SortedSet<T>

an unmodifiable view of the specified sorted set.

Annotations
@Inline:$2.$3unmodifiableSortedSet($1)
imported:Collections
See Also
Collections#unmodifiableSortedSet(SortedSet)
unmodifiableViewback to summary
public static <K, V> Map<K, V> unmodifiableView(Map<? extends K, ? extends V> map)

Returns an unmodifiable view of the specified map.

Parameters
map:Map<? extends K, ? extends V>

the map for which an unmodifiable view is to be returned. May not be null.

Returns:Map<K, V>

an unmodifiable view of the specified map.

Annotations
@Inline:$2.$3unmodifiableMap($1)
imported:Collections
See Also
Collections#unmodifiableMap(Map)
unmodifiableViewback to summary
public static <K, V> SortedMap<K, V> unmodifiableView(SortedMap<K, ? extends V> map)

Returns an unmodifiable view of the specified sorted map.

Parameters
map:SortedMap<K, ? extends V>

the sorted map for which an unmodifiable view is to be returned. May not be null.

Returns:SortedMap<K, V>

an unmodifiable view of the specified sorted map.

Annotations
@Inline:$2.$3unmodifiableSortedMap($1)
imported:Collections
See Also
Collections#unmodifiableSortedMap(SortedMap)