Top Description Fields Constructors Methods
javafx.collections

public abstract Class ObservableListBase<E>

extends AbstractList<E>
implements ObservableList<E>
Class Inheritance
All Implemented Interfaces
javafx.collections.ObservableList, javafx.beans.Observable, java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
javafx.collections.transformation.TransformationList, com.sun.javafx.collections.ElementObservableListDecorator, javafx.collections.FXCollections.UnmodifiableObservableListImpl, javafx.collections.FXCollections.CheckedObservableList, javafx.collections.ModifiableObservableListBase
Type Parameters
<E>
the type of the elements contained in the List
Imports
com.sun.javafx.collections.ListListenerHelper, java.util.AbstractList, .Arrays, .Collection, .List, javafx.beans.InvalidationListener

Abstract class that serves as a base class for ObservableList implementations. The base class provides two functionalities for the implementing classes. The following example shows how the Change build-up works:
 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 listIterator(), iterator() methods and use them in get, size() and other methods accordingly.

Since
JavaFX 8.0
See Also
ObservableList, ListChangeListener.Change, ModifiableObservableListBase

Field Summary

Modifier and TypeField and Description
private ListChangeBuilder<E>
private ListListenerHelper<E>
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
public
ObservableListBase()

Creates a default ObservableListBase.

Method Summary

Modifier and TypeMethod and Description
public boolean
addAll(E...
the elements to add
elements
)

Implements javafx.collections.ObservableList.addAll.

A convenience method for var-arg addition of elements.

public final void
addListener(InvalidationListener
The listener to register
listener
)

Implements javafx.beans.Observable.addListener.

Adds an InvalidationListener which will be notified whenever the Observable becomes invalid.

public final void
addListener(ListChangeListener<? super E>
the listener for listening to the list changes
listener
)

Implements javafx.collections.ObservableList.addListener.

Add a listener to this observable list.

protected final void
beginChange()

Begins a change block.

protected final void
endChange()

Ends the change block.

protected final void
fireChange(ListChangeListener.Change<? extends E>
an object representing the change that was done
change
)

Notifies all listeners of a change

private ListChangeBuilder<E>
protected final boolean

Returns:

true if there is a listener for this list
hasListeners
()

Returns true if there are some listeners registered for this list.

protected final void
nextAdd(int
marks the beginning (inclusive) of the range that was added
from
,
int
marks the end (exclusive) of the range that was added
to
)

Adds a new add operation to the change.

protected final void
nextPermutation(int
marks the beginning (inclusive) of the range that was permutated
from
,
int
marks the end (exclusive) of the range that was permutated
to
,
int[]
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)
perm
)

Adds a new permutation operation to the change.

protected final void
nextRemove(int
the index where the items were removed
idx
,
List<? extends E>
the list of items that were removed
removed
)

Adds a new remove operation to the change with multiple items removed.

protected final void
nextRemove(int
the index where the item was removed
idx
,
E
the item that was removed
removed
)

Adds a new remove operation to the change with single item removed.

protected final void
nextReplace(int
the index where the items were replaced
from
,
int
the end index (exclusive) of the range where the new items reside
to
,
List<? extends E>
the list of items that were removed
removed
)

Adds a new replace operation to the change.

protected final void
nextSet(int
the index of the item that was set
idx
,
E
the old value at the idx position.
old
)

Adds a new set operation to the change.

protected final void
nextUpdate(int
the position in the list where the updated element resides.
pos
)

Adds a new update operation to the change.

public void
remove(int
the start of the range to remove (inclusive)
from
,
int
the end of the range to remove (exclusive)
to
)

Implements javafx.collections.ObservableList.remove.

A simplified way of calling sublist(from, to).clear().

public boolean
removeAll(E...
the elements to be removed
elements
)

Implements javafx.collections.ObservableList.removeAll.

A convenience method for var-arg usage of the removeAll method.

public final void
removeListener(InvalidationListener
The listener to remove
listener
)

Implements javafx.beans.Observable.removeListener.

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

public final void
removeListener(ListChangeListener<? super E>
a listener to remove
listener
)

Implements javafx.collections.ObservableList.removeListener.

Tries to remove a listener from this observable list.

public boolean
retainAll(E...
the elements to be retained
elements
)

Implements javafx.collections.ObservableList.retainAll.

A convenience method for var-arg usage of the retainAll method.

public boolean
setAll(E...
the elements to set
elements
)

Implements javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all the elements passed as var-args.

public boolean
setAll(Collection<? extends E>
the collection with elements that will be added to this observableArrayList
col
)

Implements javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all elements from the collection.

Inherited from java.util.AbstractList:
addaddaddAllclearequalsgethashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveremoveRangesetsubList

Field Detail

changeBuilderback to summary
private ListChangeBuilder<E> changeBuilder
listenerHelperback to summary
private ListListenerHelper<E> listenerHelper

Constructor Detail

ObservableListBaseback to summary
public ObservableListBase()

Creates a default ObservableListBase.

Method Detail

addAllback to summary
public boolean addAll(E... elements)

Implements javafx.collections.ObservableList.addAll.

Doc from javafx.collections.ObservableList.addAll.

A convenience method for var-arg addition of elements.

Parameters
elements:E[]

the elements to add

Returns:boolean

true (as specified by Collection.add(E))

Annotations
@Override
addListenerback to summary
public final void addListener(InvalidationListener listener)

Implements javafx.beans.Observable.addListener.

Doc from javafx.beans.Observable.addListener.

Adds an InvalidationListener which will be notified whenever the Observable becomes 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 InvalidationListener instance may be safely registered for different Observables.

The Observable stores 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 calling removeListener after use or to use an instance of WeakInvalidationListener avoid this situation.

Parameters
listener:InvalidationListener

The listener to register

Annotations
@Override
addListenerback to summary
public final void addListener(ListChangeListener<? super E> listener)

Implements javafx.collections.ObservableList.addListener.

Doc from javafx.collections.ObservableList.addListener.

Add a listener to this observable list.

Parameters
listener:ListChangeListener<? super E>

the listener for listening to the list changes

Annotations
@Override
beginChangeback to summary
protected final void beginChange()

Begins a change block. Must be called before any of the next* methods is called. For every beginChange(), there must be a corresponding endChange() call.

beginChange() calls can be nested in a beginChange()/endChange() block.

See Also
endChange()
endChangeback to summary
protected final void endChange()

Ends the change block. If the block is the outer-most block for the ObservableList, the Change is constructed and all listeners are notified.

Ending a nested block doesn't fire a notification.

See Also
beginChange()
fireChangeback to summary
protected final void fireChange(ListChangeListener.Change<? extends E> change)

Notifies all listeners of a change

Parameters
change:ListChangeListener.Change<? extends E>

an object representing the change that was done

getListChangeBuilderback to summary
private ListChangeBuilder<E> getListChangeBuilder()
hasListenersback to summary
protected final boolean hasListeners()

Returns true if there are some listeners registered for this list.

Returns:boolean

true if there is a listener for this list

nextAddback to summary
protected 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:int

marks the beginning (inclusive) of the range that was added

to:int

marks the end (exclusive) of the range that was added

nextPermutationback to summary
protected 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:int

marks the beginning (inclusive) of the range that was permutated

to:int

marks the end (exclusive) of the range that was permutated

perm:int[]

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)

nextRemoveback to summary
protected final void nextRemove(int idx, List<? extends E> removed)

Adds 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:int

the index where the items were removed

removed:List<? extends E>

the list of items that were removed

nextRemoveback to summary
protected final void nextRemove(int idx, E removed)

Adds 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:int

the index where the item was removed

removed:E

the item that was removed

nextReplaceback to summary
protected final void nextReplace(int from, int to, List<? extends E> removed)

Adds a new replace operation to the change. Equivalent to nextRemove(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:int

the index where the items were replaced

to:int

the end index (exclusive) of the range where the new items reside

removed:List<? extends E>

the list of items that were removed

nextSetback to summary
protected final void nextSet(int idx, E old)

Adds a new set operation to the change. Equivalent to nextRemove(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:int

the index of the item that was set

old:E

the old value at the idx position.

nextUpdateback to summary
protected 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:int

the position in the list where the updated element resides.

removeback to summary
public void remove(int from, int to)

Implements javafx.collections.ObservableList.remove.

Doc from javafx.collections.ObservableList.remove.

A simplified way of calling sublist(from, to).clear(). As this is a common operation, ObservableList has this method for convenient usage.

Parameters
from:int

the start of the range to remove (inclusive)

to:int

the end of the range to remove (exclusive)

Annotations
@Override
removeAllback to summary
public boolean removeAll(E... elements)

Implements javafx.collections.ObservableList.removeAll.

Doc from javafx.collections.ObservableList.removeAll.

A convenience method for var-arg usage of the removeAll method.

Parameters
elements:E[]

the elements to be removed

Returns:boolean

true if list changed as a result of this call

Annotations
@Override
removeListenerback to summary
public final void removeListener(InvalidationListener listener)

Implements javafx.beans.Observable.removeListener.

Doc from javafx.beans.Observable.removeListener.

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes 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.

Parameters
listener:InvalidationListener

The listener to remove

Annotations
@Override
removeListenerback to summary
public final void removeListener(ListChangeListener<? super E> listener)

Implements javafx.collections.ObservableList.removeListener.

Doc from javafx.collections.ObservableList.removeListener.

Tries to remove a listener from this observable list. If the listener is not attached to this list, nothing happens.

Parameters
listener:ListChangeListener<? super E>

a listener to remove

Annotations
@Override
retainAllback to summary
public boolean retainAll(E... elements)

Implements javafx.collections.ObservableList.retainAll.

Doc from javafx.collections.ObservableList.retainAll.

A convenience method for var-arg usage of the retainAll method.

Parameters
elements:E[]

the elements to be retained

Returns:boolean

true if list changed as a result of this call

Annotations
@Override
setAllback to summary
public boolean setAll(E... elements)

Implements javafx.collections.ObservableList.setAll.

Doc from javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all the elements passed as var-args.

Parameters
elements:E[]

the elements to set

Returns:boolean

true (as specified by Collection.add(E))

Annotations
@Override
setAllback to summary
public boolean setAll(Collection<? extends E> col)

Implements javafx.collections.ObservableList.setAll.

Doc from javafx.collections.ObservableList.setAll.

Clears the ObservableList and adds all elements from the collection.

Parameters
col:Collection<? extends E>

the collection with elements that will be added to this observableArrayList

Returns:boolean

true (as specified by Collection.add(E))

Annotations
@Override