Class CollectionUtils
java.lang.Object
org.eclipse.gef.common.collections.CollectionUtils
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> ObservableMultiset<E>
Returns an empty, unmodifiableObservableMultiset
.static <K,
V> ObservableSetMultimap<K, V> Returns an empty, unmodifiableObservableSetMultimap
.static <E> int[]
getPermutation
(javafx.collections.ListChangeListener.Change<? extends E> change) Computes the permutation for the givenListChangeListener.Change
.static <E> List<E>
getPreviousContents
(javafx.collections.ListChangeListener.Change<E> change) Computes the previous contents of the sourceObservableList
before the givenListChangeListener.Change
was applied.static <E> javafx.collections.ObservableList<E>
Returns a (modifiable) newObservableList
wrapping anArrayList
.static <E> javafx.collections.ObservableList<E>
observableArrayList
(E... elements) Creates a newObservableList
that contains the given elements.static <E> javafx.collections.ObservableList<E>
observableArrayList
(Collection<? extends E> collection) Create a newObservableList
that is backed by anArrayList
that contains the contents of the givenCollection
.static <K,
V> ObservableSetMultimap<K, V> Returns a (modifiable) newObservableSetMultimap
wrapping aHashMultimap
.static <E> ObservableMultiset<E>
Returns a (modifiable) newObservableMultiset
wrapping aHashMultiset
.static <E> javafx.collections.ObservableList<E>
observableList
(List<E> list) Returns a (modifiable) newObservableList
wrapping the givenList
.static <E> ObservableMultiset<E>
observableMultiset
(Multiset<E> multiset) Returns a (modifiable) newObservableMultiset
wrapping the givenList
.static <K,
V> ObservableSetMultimap<K, V> observableSetMultimap
(SetMultimap<K, V> setMultimap) Returns a (modifiable) newObservableSetMultimap
wrapping the givenSetMultimap
.static <E extends Comparable<? super E>>
voidsort
(javafx.collections.ObservableList<E> observableList) Sorts the givenObservableList
using the defaultComparator
.static <E> void
sort
(javafx.collections.ObservableList<E> observableList, Comparator<? super E> comparator) Sorts the givenObservableList
using the givenComparator
.static <E> ObservableMultiset<E>
unmodifiableObservableMultiset
(ObservableMultiset<E> multiset) Returns an unmodifiableObservableMultiset
wrapping the givenObservableMultiset
.static <K,
V> ObservableSetMultimap<K, V> unmodifiableObservableSetMultimap
(ObservableSetMultimap<K, V> setMultimap) Returns an unmodifiableObservableSetMultimap
wrapping the givenObservableSetMultimap
.
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
emptyMultiset
Returns an empty, unmodifiableObservableMultiset
.- Type Parameters:
E
- The element type of theObservableMultiset
.- Returns:
- An empty, unmodifiable
ObservableMultiset
.
-
emptySetMultimap
Returns an empty, unmodifiableObservableSetMultimap
.- Type Parameters:
K
- The key type of theObservableSetMultimap
.V
- The value type of theObservableSetMultimap
.- Returns:
- An empty, unmodifiable
ObservableSetMultimap
.
-
getPermutation
public static <E> int[] getPermutation(javafx.collections.ListChangeListener.Change<? extends E> change) Computes the permutation for the givenListChangeListener.Change
.- Type Parameters:
E
- The element type of theObservableList
that was changed.- Parameters:
change
- The change, for whichListChangeListener.Change.wasPermutated()
has to returntrue
.- Returns:
- An integer array mapping previous indexes to current ones.
-
getPreviousContents
public static <E> List<E> getPreviousContents(javafx.collections.ListChangeListener.Change<E> change) Computes the previous contents of the sourceObservableList
before the givenListChangeListener.Change
was applied.- Type Parameters:
E
- The element type of theObservableList
.- Parameters:
change
- TheListChangeListener.Change
for which to compute the previous contents.- Returns:
- A newly created
List
that resembles the state of the sourceObservableList
before the change.
-
observableArrayList
public static <E> javafx.collections.ObservableList<E> observableArrayList()Returns a (modifiable) newObservableList
wrapping anArrayList
. Please note that in order to obtain proper change notifications when sorting the returnedObservableList
,sort(ObservableList)
orsort(ObservableList, Comparator)
have to be used instead ofFXCollections.sort(ObservableList)
andFXCollections.sort(ObservableList, Comparator)
. -
observableArrayList
public static <E> javafx.collections.ObservableList<E> observableArrayList(Collection<? extends E> collection) Create a newObservableList
that is backed by anArrayList
that contains the contents of the givenCollection
.- Type Parameters:
E
- The element type of theObservableList
.- Parameters:
collection
- TheCollection
that provides the initial contents of the to be createdObservableList
.- Returns:
- A new
ObservableList
containing the given contents.
-
observableArrayList
public static <E> javafx.collections.ObservableList<E> observableArrayList(E... elements) Creates a newObservableList
that contains the given elements.- Type Parameters:
E
- The element type of theObservableList
.- Parameters:
elements
- The elements that will be added to the returnedObservableList
- Returns:
- a newly created observableArrayList
-
observableHashMultimap
Returns a (modifiable) newObservableSetMultimap
wrapping aHashMultimap
.- Type Parameters:
K
- The key type of theObservableSetMultimap
.V
- The value type of theObservableSetMultimap
- Returns:
- An
ObservableSetMultimap
wrapping aHashMultimap
.
-
observableHashMultiset
Returns a (modifiable) newObservableMultiset
wrapping aHashMultiset
.- Type Parameters:
E
- The element type of theObservableList
.- Returns:
- An
ObservableMultiset
wrapping aHashMultiset
.
-
observableList
Returns a (modifiable) newObservableList
wrapping the givenList
. Please note that in order to obtain proper change notifications when sorting the returnedObservableList
,sort(ObservableList)
orsort(ObservableList, Comparator)
have to be used instead ofFXCollections.sort(ObservableList)
andFXCollections.sort(ObservableList, Comparator)
. -
observableMultiset
Returns a (modifiable) newObservableMultiset
wrapping the givenList
.- Type Parameters:
E
- The element type of theObservableList
.- Parameters:
multiset
- TheMultiset
to wrap.- Returns:
- An
ObservableMultiset
wrapping the givenList
.
-
observableSetMultimap
Returns a (modifiable) newObservableSetMultimap
wrapping the givenSetMultimap
.- Type Parameters:
K
- The key type of theObservableSetMultimap
.V
- The value type of theObservableSetMultimap
- Parameters:
setMultimap
- TheSetMultimap
to wrap.- Returns:
- An
ObservableSetMultimap
wrapping the givenList
.
-
sort
public static <E extends Comparable<? super E>> void sort(javafx.collections.ObservableList<E> observableList) Sorts the givenObservableList
using the defaultComparator
.- Type Parameters:
E
- The value type of theObservableList
.- Parameters:
observableList
- TheObservableList
to sort.
-
sort
public static <E> void sort(javafx.collections.ObservableList<E> observableList, Comparator<? super E> comparator) Sorts the givenObservableList
using the givenComparator
.- Type Parameters:
E
- The value type of theObservableList
.- Parameters:
observableList
- TheObservableList
to sort.comparator
- TheComparator
to use.
-
unmodifiableObservableMultiset
public static <E> ObservableMultiset<E> unmodifiableObservableMultiset(ObservableMultiset<E> multiset) Returns an unmodifiableObservableMultiset
wrapping the givenObservableMultiset
.- Type Parameters:
E
- The element type of theObservableMultiset
.- Parameters:
multiset
- TheObservableMultiset
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 unmodifiableObservableSetMultimap
wrapping the givenObservableSetMultimap
.- Type Parameters:
K
- The key type of theObservableSetMultimap
.V
- The value type of theObservableSetMultimap
.- Parameters:
setMultimap
- TheObservableSetMultimap
to wrap.- Returns:
- An unmodifiable wrapper around the given
ObservableSetMultimap
.
-