Class ObservableListBase<E>
- Type Parameters:
- E- the type of the elements contained in the List
- All Implemented Interfaces:
- Iterable<E>,- Collection<E>,- List<E>,- SequencedCollection<E>,- Observable,- ObservableList<E>
- Direct Known Subclasses:
- ModifiableObservableListBase,- TransformationList
ObservableList implementations.
 The base class provides two functionalities for the implementing classes.
 -  Listener handling by implementing addListenerandremoveListenermethods.fireChange(javafx.collections.ListChangeListener.Change)method is provided for notifying the listeners with aChangeobject.
-  Methods for building up a ListChangeListener.Changeobject. There are various methods callednext*, likenextAdd(int, int)for new items in the lists ornextRemove(int, java.lang.Object)for an item being removed from the list.These methods must be always enclosed in beginChange()andendChange()block.See the example below. 
  public void removeOddIndexes() {
      beginChange();
      try {
          for (int i = 1; i < size(); ++i) {
              remove(i);
          }
      } finally {
          endChange();
      }
  }
  public void remove(int i) {
      beginChange();
      try {
          E removed = ... //do some stuff that will actually remove the element at index i
          nextRemove(i, removed);
      } finally {
          endChange();
      }
  }
 
 The try/finally blocks in the example are needed only if there's a possibility for an exception to occur
 inside a beginChange() / endChange() block
 
 Note: If you want to create modifiable ObservableList implementation, consider
 using ModifiableObservableListBase as a superclass.
 
 Note: In order to create list with sequential access, you should override AbstractList.listIterator(),
 AbstractList.iterator() methods and use them in AbstractList.get(int), AbstractCollection.size() and other methods accordingly.
- Since:
- JavaFX 8.0
- See Also:
- 
Field SummaryFields declared in class java.util.AbstractListmodCount
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanA convenience method for var-arg addition of elements.final voidaddListener(InvalidationListener listener) Adds anInvalidationListenerwhich will be notified whenever theObservablebecomes invalid.final voidaddListener(ListChangeListener<? super E> listener) Add a listener to this observable list.protected final voidBegins a change block.protected final voidEnds the change block.protected final voidfireChange(ListChangeListener.Change<? extends E> change) Notifies all listeners of a changeprotected final booleanReturns true if there are some listeners registered for this list.protected final voidnextAdd(int from, int to) Adds a new add operation to the change.protected final voidnextPermutation(int from, int to, int[] perm) Adds a new permutation operation to the change.protected final voidnextRemove(int idx, E removed) Adds a new remove operation to the change with single item removed.protected final voidnextRemove(int idx, List<? extends E> removed) Adds a new remove operation to the change with multiple items removed.protected final voidnextReplace(int from, int to, List<? extends E> removed) Adds a new replace operation to the change.protected final voidAdds a new set operation to the change.protected final voidnextUpdate(int pos) Adds a new update operation to the change.voidremove(int from, int to) A simplified way of callingsublist(from, to).clear().booleanA convenience method for var-arg usage of theremoveAllmethod.final voidremoveListener(InvalidationListener listener) Removes the given listener from the list of listeners, that are notified whenever the value of theObservablebecomes invalid.final voidremoveListener(ListChangeListener<? super E> listener) Tries to remove a listener from this observable list.booleanA convenience method for var-arg usage of theretainAllmethod.booleanClears the ObservableList and adds all the elements passed as var-args.booleansetAll(Collection<? extends E> col) Clears the ObservableList and adds all elements from the collection.Methods declared in class java.util.AbstractListadd, add, addAll, clear, equals, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods declared in class java.util.AbstractCollectionaddAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toStringMethods declared in class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods declared in interface java.util.CollectionparallelStream, removeIf, stream, toArrayMethods declared in interface java.util.Listadd, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, equals, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, set, size, sort, spliterator, subList, toArray, toArrayMethods declared in interface javafx.beans.ObservablesubscribeMethods declared in interface javafx.collections.ObservableListfiltered, sorted, sorted
- 
Constructor Details- 
ObservableListBasepublic ObservableListBase()Creates a defaultObservableListBase.
 
- 
- 
Method Details- 
nextUpdateprotected final void nextUpdate(int pos) Adds a new update operation to the change.Note: needs to be called inside beginChange()/endChange()block.Note: needs to reflect the current state of the list. - Parameters:
- pos- the position in the list where the updated element resides.
 
- 
nextSetAdds a new set operation to the change. Equivalent tonextRemove(idx); nextAdd(idx, idx + 1);.Note: needs to be called inside beginChange()/endChange()block.Note: needs to reflect the current state of the list. - Parameters:
- idx- the index of the item that was set
- old- the old value at the- idxposition.
 
- 
nextReplaceAdds a new replace operation to the change. Equivalent tonextRemove(from, removed); nextAdd(from, to);Note: needs to be called inside beginChange()/endChange()block.Note: needs to reflect the current state of the list. - Parameters:
- from- the index where the items were replaced
- to- the end index (exclusive) of the range where the new items reside
- removed- the list of items that were removed
 
- 
nextRemoveAdds a new remove operation to the change with multiple items removed.Note: needs to be called inside beginChange()/endChange()block.Note: needs to reflect the current state of the list. - Parameters:
- idx- the index where the items were removed
- removed- the list of items that were removed
 
- 
nextRemoveAdds a new remove operation to the change with single item removed.Note: needs to be called inside beginChange()/endChange()block.Note: needs to reflect the current state of the list. - Parameters:
- idx- the index where the item was removed
- removed- the item that was removed
 
- 
nextPermutationprotected final void nextPermutation(int from, int to, int[] perm) Adds a new permutation operation to the change. The permutation on index"i"contains the index, where the item from the index"i"was moved.It's not necessary to provide the smallest permutation possible. It's correct to always call this method with nextPermutation(0, size(), permutation);Note: needs to be called inside beginChange()/endChange()block.Note: needs to reflect the current state of the list. - Parameters:
- from- marks the beginning (inclusive) of the range that was permutated
- to- marks the end (exclusive) of the range that was permutated
- perm- the permutation in that range. Even if- from != 0, the array should contain the indexes of the list. Therefore, such permutation would not contain indexes of range- (0, from)
 
- 
nextAddprotected final void nextAdd(int from, int to) Adds a new add operation to the change. There's no need to provide the list of added items as they can be found directly in the list under the specified indexes.Note: needs to be called inside beginChange()/endChange()block.Note: needs to reflect the current state of the list. - Parameters:
- from- marks the beginning (inclusive) of the range that was added
- to- marks the end (exclusive) of the range that was added
 
- 
beginChangeprotected final void beginChange()Begins a change block. Must be called before any of thenext*methods is called. For everybeginChange(), there must be a correspondingendChange()call.beginChange()calls can be nested in abeginChange()/endChange()block.- See Also:
 
- 
endChangeprotected final void endChange()Ends the change block. If the block is the outer-most block for theObservableList, theChangeis constructed and all listeners are notified.Ending a nested block doesn't fire a notification. - See Also:
 
- 
addListenerDescription copied from interface:ObservableAdds anInvalidationListenerwhich will be notified whenever theObservablebecomes invalid. If the same listener is added more than once, then it will be notified more than once. That is, no check is made to ensure uniqueness.Note that the same actual InvalidationListenerinstance may be safely registered for differentObservables.The Observablestores a strong reference to the listener which will prevent the listener from being garbage collected and may result in a memory leak. It is recommended to either unregister a listener by callingremoveListenerafter use or to use an instance ofWeakInvalidationListeneravoid this situation.- Specified by:
- addListenerin interface- Observable
- Parameters:
- listener- The listener to register
- See Also:
 
- 
removeListenerDescription copied from interface:ObservableRemoves the given listener from the list of listeners, that are notified whenever the value of theObservablebecomes invalid.If the given listener has not been previously registered (i.e. it was never added) then this method call is a no-op. If it had been previously added then it will be removed. If it had been added more than once, then only the first occurrence will be removed. - Specified by:
- removeListenerin interface- Observable
- Parameters:
- listener- The listener to remove
- See Also:
 
- 
addListenerDescription copied from interface:ObservableListAdd a listener to this observable list.- Specified by:
- addListenerin interface- ObservableList<E>
- Parameters:
- listener- the listener for listening to the list changes
 
- 
removeListenerDescription copied from interface:ObservableListTries to remove a listener from this observable list. If the listener is not attached to this list, nothing happens.- Specified by:
- removeListenerin interface- ObservableList<E>
- Parameters:
- listener- a listener to remove
 
- 
fireChangeNotifies all listeners of a change- Parameters:
- change- an object representing the change that was done
 
- 
hasListenersprotected final boolean hasListeners()Returns true if there are some listeners registered for this list.- Returns:
- true if there is a listener for this list
 
- 
addAllDescription copied from interface:ObservableListA convenience method for var-arg addition of elements.- Specified by:
- addAllin interface- ObservableList<E>
- Parameters:
- elements- the elements to add
- Returns:
- true (as specified by Collection.add(E))
 
- 
setAllDescription copied from interface:ObservableListClears the ObservableList and adds all the elements passed as var-args.- Specified by:
- setAllin interface- ObservableList<E>
- Parameters:
- elements- the elements to set
- Returns:
- true (as specified by Collection.add(E))
 
- 
setAllDescription copied from interface:ObservableListClears the ObservableList and adds all elements from the collection.- Specified by:
- setAllin interface- ObservableList<E>
- Parameters:
- col- the collection with elements that will be added to this observableArrayList
- Returns:
- true (as specified by Collection.add(E))
 
- 
removeAllDescription copied from interface:ObservableListA convenience method for var-arg usage of theremoveAllmethod.- Specified by:
- removeAllin interface- ObservableList<E>
- Parameters:
- elements- the elements to be removed
- Returns:
- true if list changed as a result of this call
 
- 
retainAllDescription copied from interface:ObservableListA convenience method for var-arg usage of theretainAllmethod.- Specified by:
- retainAllin interface- ObservableList<E>
- Parameters:
- elements- the elements to be retained
- Returns:
- true if list changed as a result of this call
 
- 
removepublic void remove(int from, int to) Description copied from interface:ObservableListA simplified way of callingsublist(from, to).clear(). As this is a common operation, ObservableList has this method for convenient usage.- Specified by:
- removein interface- ObservableList<E>
- Parameters:
- from- the start of the range to remove (inclusive)
- to- the end of the range to remove (exclusive)
 
 
-