API REVIEW: BaseObservableList

Martin Sladecek martin.sladecek at oracle.com
Thu Jun 28 01:16:35 PDT 2012

BaseObservableList was already discussed for 2.1, but we decided to 
defer it to some later release at the end. Full discussion here: 

Based on the discussion, I reworked it into two new classes: 
BaseObservableList (for simple observable lists that are not necessarily 
modifiable) and it's subclass BaseModifiableObservableList.

*public abstract class BaseObservableList<E> extends AbstractList<E> 
implements ObservableList<E>:*

First of all, it will implement following ObservableList methods:

public final void addListener(InvalidationListener listener)
public final void removeListener(InvalidationListener listener)
public final void addListener(ListChangeListener<? super E> listener)
public final void removeListener(ListChangeListener<? super E> listener)

... and will contain these new methods:

// calls all the listeners of this ObservableList
protected final void callListeners(ListChangeListener.Change<E> change)
// true if there are some registered listeners
protected final boolean hasListeners()

Following methods were part of IterableChangeBuilder in the original 
discussion. Now they will be part of BaseObservableList and can be used 
for creating a Change and firing it, so you don't need to create 
subclasses of ListChangeListener.Change yourself.

protected final void nextUpdate(int pos)
protected final void nextSet(int idx, E old)
protected final void nextReplace(int from, int to, ArrayList removed)
protected final void nextRemove(int idx, List removed)
protected final void nextRemove(int idx, E removed)
protected final void nextPermutation(int from, int to, int[] perm)
protected final void nextAdd(int from, int to)
protected final void endChange()
protected final void beginChange()

All next* methods need to be enclosed in beginChange() / endChange() 
pair. The calls can be also nested and after the outermost endChange() 
call, callListeners() will be called with the newly created Change.

*public abstract class BaseModifiableObservableList<E> extends 
This class introduces three new abstract methods:

  protected abstract void doAdd(int index, E element);
  protected abstract E doSet(int index, E element);
  protected abstract E doRemove(int index);

These methods are meant to contain simple list manipulations. The 
BaseModifiableObservableList implementation takes care of Change 
construction (using BaseObservableList methods), but subclasses can 
override this behaviour.

Any comments?


More information about the openjfx-dev mailing list