Class CollectionUtils
- java.lang.Object
-
- org.eclipse.gef.common.collections.CollectionUtils
-
public class CollectionUtils extends java.lang.Object
TheCollectionUtils
contains a method to compute the old value of anObservableList
for a givenListChangeListener.Change
event. For details, seegetPreviousContents(javafx.collections.ListChangeListener.Change)
.
-
-
Constructor Summary
Constructors Constructor Description CollectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> ObservableMultiset<E>
emptyMultiset()
Returns an empty, unmodifiableObservableMultiset
.static <K,V>
ObservableSetMultimap<K,V>emptySetMultimap()
Returns an empty, unmodifiableObservableSetMultimap
.static <E> int[]
getPermutation(javafx.collections.ListChangeListener.Change<? extends E> change)
Computes the permutation for the givenListChangeListener.Change
.static <E> java.util.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>
observableArrayList()
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(java.util.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>observableHashMultimap()
Returns a (modifiable) newObservableSetMultimap
wrapping aHashMultimap
.static <E> ObservableMultiset<E>
observableHashMultiset()
Returns a (modifiable) newObservableMultiset
wrapping aHashMultiset
.static <E> javafx.collections.ObservableList<E>
observableList(java.util.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 java.lang.Comparable<? super E>>
voidsort(javafx.collections.ObservableList<E> observableList)
Sorts the givenObservableList
using the defaultComparator
.static <E> void
sort(javafx.collections.ObservableList<E> observableList, java.util.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
.
-
-
-
Method Detail
-
emptyMultiset
public static <E> ObservableMultiset<E> emptyMultiset()
Returns an empty, unmodifiableObservableMultiset
.- Type Parameters:
E
- The element type of theObservableMultiset
.- Returns:
- An empty, unmodifiable
ObservableMultiset
.
-
emptySetMultimap
public static <K,V> ObservableSetMultimap<K,V> 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> java.util.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)
.- Type Parameters:
E
- The element type of theObservableList
. TheList
to wrap.- Returns:
- An
ObservableList
wrapping the givenList
.
-
observableArrayList
public static <E> javafx.collections.ObservableList<E> observableArrayList(java.util.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
public static <K,V> ObservableSetMultimap<K,V> 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
public static <E> ObservableMultiset<E> observableHashMultiset()
Returns a (modifiable) newObservableMultiset
wrapping aHashMultiset
.- Type Parameters:
E
- The element type of theObservableList
.- Returns:
- An
ObservableMultiset
wrapping aHashMultiset
.
-
observableList
public static <E> javafx.collections.ObservableList<E> observableList(java.util.List<E> list)
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)
.- Type Parameters:
E
- The element type of theObservableList
.- Parameters:
list
- TheList
to wrap.- Returns:
- An
ObservableList
wrapping the givenList
.
-
observableMultiset
public static <E> ObservableMultiset<E> observableMultiset(Multiset<E> multiset)
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
public static <K,V> ObservableSetMultimap<K,V> observableSetMultimap(SetMultimap<K,V> setMultimap)
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 java.lang.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, java.util.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
.
-
-