org.eclipse.xtext.xbase.lib
Class CollectionExtensions

java.lang.Object
  extended by org.eclipse.xtext.xbase.lib.CollectionExtensions

@GwtCompatible
public class CollectionExtensions
extends Object

This is an extension library for collections.

Author:
Sven Efftinge - Initial contribution and API, Sebastian Zarnekow

Constructor Summary
CollectionExtensions()
           
 
Method Summary
static
<T> boolean
addAll(Collection<? super T> collection, T... elements)
          Adds all of the specified elements to the specified collection.
static
<T> boolean
addAll(Collection<T> collection, Iterable<? extends T> elements)
          Adds all of the specified elements to the specified collection.
static
<T> List<T>
immutableCopy(List<? extends T> list)
          Returns an immutable copy of the specified list.
static
<K,V> Map<K,V>
immutableCopy(Map<? extends K,? extends V> map)
          Returns an immutable copy of the specified map.
static
<T> Set<T>
immutableCopy(Set<? extends T> set)
          Returns an immutable copy of the specified set.
static
<K,V> SortedMap<K,V>
immutableCopy(SortedMap<K,? extends V> map)
          Returns an immutable copy of the specified sorted map.
static
<T> SortedSet<T>
immutableCopy(SortedSet<T> set)
          Returns an immutable copy of the specified sorted set.
static
<E> boolean
operator_add(Collection<? super E> collection, E value)
          The operator mapping from += to Collection.add(Object).
static
<E> boolean
operator_add(Collection<E> collection, Iterable<? extends E> newElements)
          The operator mapping from += to addAll(Collection, Iterable).
static
<E> boolean
operator_remove(Collection<? super E> collection, E value)
          The operator mapping from -= to Collection.remove(Object).
static
<E> boolean
operator_remove(Collection<E> collection, Collection<? extends E> newElements)
          The operator mapping from -= to removeAll(Collection, Collection).
static
<T> boolean
removeAll(Collection<? super T> collection, T... elements)
          Removes all of the specified elements from the specified collection.
static
<T> boolean
removeAll(Collection<T> collection, Collection<? extends T> elements)
          Removes all of the specified elements from the specified collection.
static
<T> boolean
removeAll(Collection<T> collection, Iterable<? extends T> elements)
          Removes all of the specified elements from the specified collection.
static
<T> Collection<T>
unmodifiableView(Collection<? extends T> collection)
          Returns an unmodifiable view of the specified collection.
static
<T> List<T>
unmodifiableView(List<? extends T> list)
          Returns an unmodifiable view of the specified list.
static
<K,V> Map<K,V>
unmodifiableView(Map<? extends K,? extends V> map)
          Returns an unmodifiable view of the specified map.
static
<T> Set<T>
unmodifiableView(Set<? extends T> set)
          Returns an unmodifiable view of the specified set.
static
<K,V> SortedMap<K,V>
unmodifiableView(SortedMap<K,? extends V> map)
          Returns an unmodifiable view of the specified sorted map.
static
<T> SortedSet<T>
unmodifiableView(SortedSet<T> set)
          Returns an unmodifiable view of the specified sorted set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionExtensions

public CollectionExtensions()
Method Detail

operator_add

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 - the to-be-changed collection. May not be null.
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(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 - the to-be-changed collection. May not be null.
newElements - elements to be inserted into the collection. May not be null but may contain null elements if the the target collection supports null elements.
Returns:
true if the collection changed due to this operation.
See Also:
addAll(Collection, Iterable)

operator_remove

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 - the to-be-changed collection. May not be null.
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(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 - the to-be-changed collection. May not be null.
newElements - elements to be removed from the collection. May not be null but may contain null elements if the the target collection supports null elements.
Returns:
true if the collection changed due to this operation.
Since:
2.4
See Also:
removeAll(Collection, Collection)

unmodifiableView

public static <T> List<T> unmodifiableView(List<? extends T> list)
Returns an unmodifiable view of the specified list.

Parameters:
list - the list for which an unmodifiable view is to be returned. May not be null.
Returns:
an unmodifiable view of the specified list.
See Also:
Collections.unmodifiableList(List)

unmodifiableView

public static <T> Collection<T> unmodifiableView(Collection<? extends T> collection)
Returns an unmodifiable view of the specified collection.

Parameters:
collection - the collection for which an unmodifiable view is to be returned. May not be null.
Returns:
an unmodifiable view of the specified collection.
See Also:
Collections.unmodifiableCollection(Collection)

unmodifiableView

public static <T> Set<T> unmodifiableView(Set<? extends T> set)
Returns an unmodifiable view of the specified set.

Parameters:
set - the set for which an unmodifiable view is to be returned. May not be null.
Returns:
an unmodifiable view of the specified set.
See Also:
Collections.unmodifiableSet(Set)

unmodifiableView

public static <T> SortedSet<T> unmodifiableView(SortedSet<T> set)
Returns an unmodifiable view of the specified sorted set.

Parameters:
set - the sorted set for which an unmodifiable view is to be returned. May not be null.
Returns:
an unmodifiable view of the specified sorted set.
See Also:
Collections.unmodifiableSortedSet(SortedSet)

unmodifiableView

public static <K,V> Map<K,V> unmodifiableView(Map<? extends K,? extends V> map)
Returns an unmodifiable view of the specified map.

Parameters:
map - the map for which an unmodifiable view is to be returned. May not be null.
Returns:
an unmodifiable view of the specified map.
See Also:
Collections.unmodifiableMap(Map)

unmodifiableView

public static <K,V> SortedMap<K,V> unmodifiableView(SortedMap<K,? extends V> map)
Returns an unmodifiable view of the specified sorted map.

Parameters:
map - the sorted map for which an unmodifiable view is to be returned. May not be null.
Returns:
an unmodifiable view of the specified sorted map.
See Also:
Collections.unmodifiableSortedMap(SortedMap)

immutableCopy

public static <T> List<T> immutableCopy(List<? extends T> list)
Returns an immutable copy of the specified list.

Parameters:
list - the list for which an immutable copy should be created. May not be null.
Returns:
an immutable copy of the specified list.

immutableCopy

public static <T> Set<T> immutableCopy(Set<? extends T> set)
Returns an immutable copy of the specified set.

Parameters:
set - the set for which an immutable copy should be created. May not be null.
Returns:
an immutable copy of the specified set.

immutableCopy

public static <T> SortedSet<T> immutableCopy(SortedSet<T> set)
Returns an immutable copy of the specified sorted set.

Parameters:
set - the sorted set for which an immutable copy should be created. May not be null.
Returns:
an immutable copy of the specified sorted set.

immutableCopy

public static <K,V> Map<K,V> immutableCopy(Map<? extends K,? extends V> map)
Returns an immutable copy of the specified map.

Parameters:
map - the map for which an immutable copy should be created. May not be null.
Returns:
an immutable copy of the specified map.

immutableCopy

public static <K,V> SortedMap<K,V> immutableCopy(SortedMap<K,? extends V> map)
Returns an immutable copy of the specified sorted map.

Parameters:
map - the sorted map for which an immutable copy should be created. May not be null.
Returns:
an immutable copy of the specified sorted map.

addAll

public static <T> boolean addAll(Collection<? super T> collection,
                                 T... elements)
Adds all of the specified elements to the specified collection.

Parameters:
collection - the collection into which the elements are to be inserted. May not be null.
elements - the elements to insert into the collection. May not be null but may contain null entries if the collection allows that.
Returns:
true if the collection changed as a result of the call

addAll

public static <T> boolean addAll(Collection<T> collection,
                                 Iterable<? extends T> elements)
Adds all of the specified elements to the specified collection.

Parameters:
collection - the collection into which the elements are to be inserted. May not be null.
elements - the elements to insert into the collection. May not be null but may contain null entries if the collection allows that.
Returns:
true if the collection changed as a result of the call

removeAll

public static <T> boolean removeAll(Collection<? super T> collection,
                                    T... elements)
Removes all of the specified elements from the specified collection.

Parameters:
collection - the collection from which the elements are to be removed. May not be null.
elements - the elements be remove from the collection. May not be null but may contain null entries if the collection allows that.
Returns:
true if the collection changed as a result of the call
Since:
2.4

removeAll

public static <T> boolean removeAll(Collection<T> collection,
                                    Collection<? extends T> elements)
Removes all of the specified elements from the specified collection.

Parameters:
collection - the collection from which the elements are to be removed. May not be null.
elements - the elements to remove from the collection. May not be null but may contain null entries if the collection allows that.
Returns:
true if the collection changed as a result of the call
Since:
2.4

removeAll

public static <T> boolean removeAll(Collection<T> collection,
                                    Iterable<? extends T> elements)
Removes all of the specified elements from the specified collection.

Parameters:
collection - the collection from which the elements are to be removed. May not be null.
elements - the elements to remove from the collection. May not be null but may contain null entries if the collection allows that.
Returns:
true if the collection changed as a result of the call
Since:
2.4


Copyright © 2013. All Rights Reserved.