Package javafx.collections
Class FXCollections
java.lang.Object
javafx.collections.FXCollections
Utility class that consists of static methods that are 1:1 copies of java.util.Collections methods.
The wrapper methods (like synchronizedObservableList or emptyObservableList) has exactly the same functionality as the methods in Collections, with exception that they return ObservableList and are therefore suitable for methods that require ObservableList on input.
The utility methods are here mainly for performance reasons. All methods are optimized in a way that they yield only limited number of notifications. On the other hand, java.util.Collections methods might call "modification methods" on an ObservableList multiple times, resulting in a number of notifications.
The wrapper methods (like synchronizedObservableList or emptyObservableList) has exactly the same functionality as the methods in Collections, with exception that they return ObservableList and are therefore suitable for methods that require ObservableList on input.
The utility methods are here mainly for performance reasons. All methods are optimized in a way that they yield only limited number of notifications. On the other hand, java.util.Collections methods might call "modification methods" on an ObservableList multiple times, resulting in a number of notifications.
- Since:
- JavaFX 2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> ObservableList<E>
concat
(ObservableList<E>... lists) Concatenates more observable lists into one.static <T> void
copy
(ObservableList<? super T> dest, List<? extends T> src) Copies elements from src to dest.static <E> ObservableList<E>
Creates and empty unmodifiable observable list.static <T> void
fill
(ObservableList<? super T> list, T obj) Fills the provided list with obj.static <E> ObservableList<E>
Creates a new empty observable list that is backed by an arraylist.static <E> ObservableList<E>
observableArrayList
(E... items) Creates a new observable array list withitems
added to it.static <E> ObservableList<E>
observableArrayList
(Collection<? extends E> col) Creates a new observable array list and adds a content of collectioncol
to it.static <E> ObservableList<E>
observableArrayList
(Callback<E, Observable[]> extractor) Creates a new empty observable list backed by an arraylist.static <K,
V> ObservableMap<K, V> Creates a new empty observable map that is backed by a HashMap.static <E> ObservableList<E>
observableList
(List<E> list) Constructs an ObservableList that is backed by the specified list.static <E> ObservableList<E>
observableList
(List<E> list, Callback<E, Observable[]> extractor) Constructs an ObservableList that is backed by the specified list.static <K,
V> ObservableMap<K, V> observableMap
(Map<K, V> map) Constructs an ObservableMap that is backed by the specified map.static <E> ObservableSet<E>
observableSet
(E... elements) Constructs an ObservableSet backed by a HashSet that contains all the specified elements.static <E> ObservableSet<E>
observableSet
(Set<E> set) Constructs an ObservableSet that is backed by the specified set.static <T> boolean
replaceAll
(ObservableList<T> list, T oldVal, T newVal) Replace all oldVal elements in the list with newVal element.static void
reverse
(ObservableList list) Reverse the order in the list Fires only one change notification on the list.static void
rotate
(ObservableList list, int distance) Rotates the list by distance.static void
shuffle
(ObservableList<?> list) Shuffles all elements in the observable list.static void
shuffle
(ObservableList list, Random rnd) Shuffles all elements in the observable list.static <E> ObservableList<E>
Creates an unmodifiable observable list with single element.static <T extends Comparable<? super T>>
voidsort
(ObservableList<T> list) Sorts the provided observable list.static <T> void
sort
(ObservableList<T> list, Comparator<? super T> c) Sorts the provided observable list using the c comparator.static <E> ObservableList<E>
synchronizedObservableList
(ObservableList<E> list) Creates and returns a synchronized wrapper on top of provided observable list.static <E> ObservableList<E>
unmodifiableObservableList
(ObservableList<E> list) Creates and returns unmodifiable wrapper list on top of provided observable list.
-
Method Details
-
observableList
Constructs an ObservableList that is backed by the specified list. Mutation operations on the ObservableList instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying list are not reported to observers of any ObservableList that wraps it.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
list
- a concrete List that backs this ObservableList- Returns:
- a newly created ObservableList
-
observableList
public static <E> ObservableList<E> observableList(List<E> list, Callback<E, Observable[]> extractor) Constructs an ObservableList that is backed by the specified list. Mutation operations on the ObservableList instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying list are not reported to observers of any ObservableList that wraps it.
This list also reports mutations of the elements in it by usingextractor
. Observable objects returned by extractor (applied to each list element) are listened for changes and transformed into "update" change of ListChangeListener.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
list
- a concrete List that backs this ObservableListextractor
- element to Observable[] convertor- Returns:
- a newly created ObservableList
- Since:
- JavaFX 2.1
-
observableMap
Constructs an ObservableMap that is backed by the specified map. Mutation operations on the ObservableMap instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying map are not reported to observers of any ObservableMap that wraps it.- Type Parameters:
K
- the type of the wrapped keyV
- the type of the wrapped value- Parameters:
map
- a Map that backs this ObservableMap- Returns:
- a newly created ObservableMap
-
observableSet
Constructs an ObservableSet that is backed by the specified set. Mutation operations on the ObservableSet instance will be reported to observers that have registered on that instance.
Note that mutation operations made directly to the underlying set are not reported to observers of any ObservableSet that wraps it.- Parameters:
set
- a Set that backs this ObservableSet- Returns:
- a newly created ObservableSet
- Since:
- JavaFX 2.1
-
observableSet
Constructs an ObservableSet backed by a HashSet that contains all the specified elements.- Parameters:
elements
- elements that will be added into returned ObservableSet- Returns:
- a newly created ObservableSet
- Since:
- JavaFX 2.1
-
observableArrayList
Creates a new empty observable list that is backed by an arraylist.- Type Parameters:
E
- The type of List to be wrapped- Returns:
- a newly created ObservableList
- See Also:
-
observableArrayList
Creates a new empty observable list backed by an arraylist. This list reports element updates.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
extractor
- element to Observable[] convertor. Observable objects are listened for changes on the element.- Returns:
- a newly created ObservableList
- Since:
- JavaFX 2.1
- See Also:
-
observableArrayList
Creates a new observable array list withitems
added to it.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
items
- the items that will be in the new observable ArrayList- Returns:
- a newly created observableArrayList
- See Also:
-
observableArrayList
Creates a new observable array list and adds a content of collectioncol
to it.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
col
- a collection which content should be added to the observableArrayList- Returns:
- a newly created observableArrayList
-
observableHashMap
Creates a new empty observable map that is backed by a HashMap.- Type Parameters:
K
- the type of the wrapped keyV
- the type of the wrapped value- Returns:
- a newly created observable HashMap
-
concat
Concatenates more observable lists into one. The resulting list would be backed by an arraylist.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
lists
- lists to concatenate- Returns:
- new observable array list concatenated from the arguments
-
unmodifiableObservableList
Creates and returns unmodifiable wrapper list on top of provided observable list.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
list
- an ObservableList that is to be wrapped- Returns:
- an ObserableList wrapper that is unmodifiable
- See Also:
-
synchronizedObservableList
Creates and returns a synchronized wrapper on top of provided observable list.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
list
- the list to be "wrapped" in a synchronized list.- Returns:
- A synchronized version of the observable list
- See Also:
-
emptyObservableList
Creates and empty unmodifiable observable list.- Type Parameters:
E
- The type of List to be wrapped- Returns:
- An empty unmodifiable observable list
- See Also:
-
singletonObservableList
Creates an unmodifiable observable list with single element.- Type Parameters:
E
- The type of List to be wrapped- Parameters:
e
- the only elements that will be contained in this singleton observable list- Returns:
- a singleton observable list
- See Also:
-
copy
Copies elements from src to dest. Fires only one change notification on dest.- Type Parameters:
T
- The type of List to be wrapped- Parameters:
dest
- the destination observable listsrc
- the source list- See Also:
-
fill
Fills the provided list with obj. Fires only one change notification on the list.- Type Parameters:
T
- The type of List to be wrapped- Parameters:
list
- the list to fillobj
- the object to fill the list with- See Also:
-
replaceAll
Replace all oldVal elements in the list with newVal element. Fires only one change notification on the list.- Type Parameters:
T
- The type of List to be wrapped- Parameters:
list
- the list which will have it's elements replacedoldVal
- the element that is going to be replacenewVal
- the replacement- Returns:
- true if the list was modified
- See Also:
-
reverse
Reverse the order in the list Fires only one change notification on the list.- Parameters:
list
- the list to be reversed- See Also:
-
rotate
Rotates the list by distance. Fires only one change notification on the list.- Parameters:
list
- the list to be rotateddistance
- the distance of rotation- See Also:
-
shuffle
Shuffles all elements in the observable list. Fires only one change notification on the list.- Parameters:
list
- the list to shuffle- See Also:
-
shuffle
Shuffles all elements in the observable list. Fires only one change notification on the list.- Parameters:
list
- the list to be shuffledrnd
- the random generator used for shuffling- See Also:
-
sort
Sorts the provided observable list. Fires only one change notification on the list.- Type Parameters:
T
- The type of List to be wrapped- Parameters:
list
- the list to be sorted- See Also:
-
sort
Sorts the provided observable list using the c comparator. Fires only one change notification on the list.- Type Parameters:
T
- The type of List to be wrapped- Parameters:
list
- the list to sortc
- comparator used for sorting. Null if natural ordering is required.- See Also:
-