Package org.eclipse.gef.common.collections

# Class CollectionUtils

java.lang.Object
org.eclipse.gef.common.collections.CollectionUtils

public class CollectionUtils extends Object
The `CollectionUtils` contains a method to compute the old value of an `ObservableList` for a given `ListChangeListener.Change` event. For details, see `getPreviousContents(javafx.collections.ListChangeListener.Change)`.

## Constructor Summary

Constructors
Constructor
Description
`CollectionUtils()`

## Method Summary

Modifier and Type
Method
Description
`static <E> ObservableMultiset<E>`
`emptyMultiset()`
Returns an empty, unmodifiable `ObservableMultiset`.
`static <K, V> ObservableSetMultimap<K,V>`
`emptySetMultimap()`
Returns an empty, unmodifiable `ObservableSetMultimap`.
`static <E> int[]`
`getPermutation(ListChangeListener.Change<? extends E> change)`
Computes the permutation for the given `ListChangeListener.Change`.
`static <E> List<E>`
`getPreviousContents(ListChangeListener.Change<E> change)`
Computes the previous contents of the source `ObservableList` before the given `ListChangeListener.Change` was applied.
`static <E> ObservableList<E>`
`observableArrayList()`
Returns a (modifiable) new `ObservableList` wrapping an `ArrayList`.
`static <E> ObservableList<E>`
`observableArrayList(E... elements)`
Creates a new `ObservableList` that contains the given elements.
`static <E> ObservableList<E>`
`observableArrayList(Collection<? extends E> collection)`
Create a new `ObservableList` that is backed by an `ArrayList` that contains the contents of the given `Collection`.
`static <K, V> ObservableSetMultimap<K,V>`
`observableHashMultimap()`
Returns a (modifiable) new `ObservableSetMultimap` wrapping a `HashMultimap`.
`static <E> ObservableMultiset<E>`
`observableHashMultiset()`
Returns a (modifiable) new `ObservableMultiset` wrapping a `HashMultiset`.
`static <E> ObservableList<E>`
`observableList(List<E> list)`
Returns a (modifiable) new `ObservableList` wrapping the given `List`.
`static <E> ObservableMultiset<E>`
`observableMultiset(Multiset<E> multiset)`
Returns a (modifiable) new `ObservableMultiset` wrapping the given `List`.
`static <K, V> ObservableSetMultimap<K,V>`
`observableSetMultimap(SetMultimap<K,V> setMultimap)`
Returns a (modifiable) new `ObservableSetMultimap` wrapping the given `SetMultimap`.
`static <E extends Comparable<? super E>>
void`
`sort(ObservableList<E> observableList)`
Sorts the given `ObservableList` using the default `Comparator` .
`static <E> void`
`sort(ObservableList<E> observableList, Comparator<? super E> comparator)`
Sorts the given `ObservableList` using the given `Comparator` .
`static <E> ObservableMultiset<E>`
`unmodifiableObservableMultiset(ObservableMultiset<E> multiset)`
Returns an unmodifiable `ObservableMultiset` wrapping the given `ObservableMultiset`.
`static <K, V> ObservableSetMultimap<K,V>`
`unmodifiableObservableSetMultimap(ObservableSetMultimap<K,V> setMultimap)`
Returns an unmodifiable `ObservableSetMultimap` wrapping the given `ObservableSetMultimap`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CollectionUtils

public CollectionUtils()

## Method Details

### emptyMultiset

public static <E> ObservableMultiset<E> emptyMultiset()
Returns an empty, unmodifiable `ObservableMultiset`.

Type Parameters:
  `E` - The element type of the `ObservableMultiset`.
Returns:
  An empty, unmodifiable `ObservableMultiset`.

### emptySetMultimap

public static <K, V> ObservableSetMultimap<K,V> emptySetMultimap()
Returns an empty, unmodifiable `ObservableSetMultimap`.

Type Parameters:
  `K` - The key type of the `ObservableSetMultimap`.
  `V` - The value type of the `ObservableSetMultimap`.
Returns:
  An empty, unmodifiable `ObservableSetMultimap`.

### getPermutation

public static <E> int[] getPermutation(ListChangeListener.Change<? extends E> change)
Computes the permutation for the given `ListChangeListener.Change`.

Type Parameters:
  `E` - The element type of the `ObservableList` that was changed.
Parameters:
  `change` - The change, for which `ListChangeListener.Change.wasPermutated()` has to return `true`.
Returns:
  An integer array mapping previous indexes to current ones.

### getPreviousContents

public static <E> List<E> getPreviousContents(ListChangeListener.Change<E> change)
Computes the previous contents of the source `ObservableList` before the given `ListChangeListener.Change` was applied.

Type Parameters:
  `E` - The element type of the `ObservableList`.
Parameters:
  `change` - The `ListChangeListener.Change` for which to compute the previous contents.
Returns:
  A newly created `List` that resembles the state of the source `ObservableList` before the change.

### observableArrayList

public static <E> ObservableList<E> observableArrayList()
Returns a (modifiable) new `ObservableList` wrapping an `ArrayList`. Please note that in order to obtain proper change notifications when sorting the returned `ObservableList`, `sort(ObservableList)` or `sort(ObservableList, Comparator)` have to be used instead of `FXCollections.sort(ObservableList)` and `FXCollections.sort(ObservableList, Comparator)`.

Type Parameters:
  `E` - The element type of the `ObservableList`. The `List` to wrap.
Returns:
  An `ObservableList` wrapping the given `List`.

### observableArrayList

public static <E> ObservableList<E> observableArrayList(Collection<? extends E> collection)
Create a new `ObservableList` that is backed by an `ArrayList` that contains the contents of the given `Collection`.

Type Parameters:
  `E` - The element type of the `ObservableList`.
Parameters:
  `collection` - The `Collection` that provides the initial contents of the to be created `ObservableList`.
Returns:
  A new `ObservableList` containing the given contents.

### observableArrayList

public static <E> ObservableList<E> observableArrayList(E... elements)
Creates a new `ObservableList` that contains the given elements.

Type Parameters:
  `E` - The element type of the `ObservableList`.
Parameters:
  `elements` - The elements that will be added to the returned `ObservableList`
Returns:
  a newly created observableArrayList

### observableHashMultimap

public static <K, V> ObservableSetMultimap<K,V> observableHashMultimap()
Returns a (modifiable) new `ObservableSetMultimap` wrapping a `HashMultimap`.

Type Parameters:
  `K` - The key type of the `ObservableSetMultimap`.
  `V` - The value type of the `ObservableSetMultimap`
Returns:
  An `ObservableSetMultimap` wrapping a `HashMultimap`.

### observableHashMultiset

public static <E> ObservableMultiset<E> observableHashMultiset()
Returns a (modifiable) new `ObservableMultiset` wrapping a `HashMultiset`.

Type Parameters:
  `E` - The element type of the `ObservableList`.
Returns:
  An `ObservableMultiset` wrapping a `HashMultiset`.

### observableList

public static <E> ObservableList<E> observableList(List<E> list)
Returns a (modifiable) new `ObservableList` wrapping the given `List`. Please note that in order to obtain proper change notifications when sorting the returned `ObservableList`, `sort(ObservableList)` or `sort(ObservableList, Comparator)` have to be used instead of `FXCollections.sort(ObservableList)` and `FXCollections.sort(ObservableList, Comparator)`.

Type Parameters:
  `E` - The element type of the `ObservableList`.
Parameters:
  `list` - The `List` to wrap.
Returns:
  An `ObservableList` wrapping the given `List`.

### observableMultiset

public static <E> ObservableMultiset<E> observableMultiset(Multiset<E> multiset)
Returns a (modifiable) new `ObservableMultiset` wrapping the given `List`.

Type Parameters:
  `E` - The element type of the `ObservableList`.
Parameters:
  `multiset` - The `Multiset` to wrap.
Returns:
  An `ObservableMultiset` wrapping the given `List`.

### observableSetMultimap

public static <K, V> ObservableSetMultimap<K,V> observableSetMultimap(SetMultimap<K,V> setMultimap)
Returns a (modifiable) new `ObservableSetMultimap` wrapping the given `SetMultimap`.

Type Parameters:
  `K` - The key type of the `ObservableSetMultimap`.
  `V` - The value type of the `ObservableSetMultimap`
Parameters:
  `setMultimap` - The `SetMultimap` to wrap.
Returns:
  An `ObservableSetMultimap` wrapping the given `List`.

### sort

public static <E extends Comparable<? super E>> void sort(ObservableList<E> observableList)
Sorts the given `ObservableList` using the default `Comparator` .

Type Parameters:
  `E` - The value type of the `ObservableList`.
Parameters:
  `observableList` - The `ObservableList` to sort.

### sort

public static <E> void sort(ObservableList<E> observableList, Comparator<? super E> comparator)
Sorts the given `ObservableList` using the given `Comparator` .

Type Parameters:
  `E` - The value type of the `ObservableList`.
Parameters:
  `observableList` - The `ObservableList` to sort.
  `comparator` - The `Comparator` to use.

### unmodifiableObservableMultiset

public static <E> ObservableMultiset<E> unmodifiableObservableMultiset(ObservableMultiset<E> multiset)
Returns an unmodifiable `ObservableMultiset` wrapping the given `ObservableMultiset`.

Type Parameters:
  `E` - The element type of the `ObservableMultiset`.
Parameters:
  `multiset` - The `ObservableMultiset` to wrap.
Returns:
  An unmodifiable wrapper around the given `ObservableMultiset`.

### unmodifiableObservableSetMultimap

public static <K, V> ObservableSetMultimap<K,V> unmodifiableObservableSetMultimap(ObservableSetMultimap<K,V> setMultimap)
Returns an unmodifiable `ObservableSetMultimap` wrapping the given `ObservableSetMultimap`.

Type Parameters:
  `K` - The key type of the `ObservableSetMultimap`.
  `V` - The value type of the `ObservableSetMultimap`.
Parameters:
  `setMultimap` - The `ObservableSetMultimap` to wrap.
Returns:
  An unmodifiable wrapper around the given `ObservableSetMultimap`.