API REVIEW: BaseObservableList

Richard Bair richard.bair at oracle.com
Fri Nov 2 10:49:21 PDT 2012

> Hello,
> BaseObservableList was already discussed for 2.1, but we decided to defer it to some later release at the end. Full discussion here: http://mail.openjdk.java.net/pipermail/openjfx-dev/2011-December/000224.html.
> 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.

Our naming convention is FooBase rather than BaseFoo, so these should be ObservableListBase, ModifiableObservableListBase.

> *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)

I think we're using the term "fire" elsewhere rather than "call", so this should probably be "fire(ListChangeListener.Change<E> change)" instead.

> // true if there are some registered listeners
> protected final boolean hasListeners()

The name "hasListeners" is great, but a bummer it isn't recognized by JavaBeans as a getter. Then again, this isn't really a getter because we're not providing a ReadOnlyProperty (and this is a mutable state). So lets keep "has".

> 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.

It seems odd that these are on the base class itself. I don't remember the previous conversation so maybe I said something different before :-). Steve, I'm wondering what you think on this point?

> *public abstract class BaseModifiableObservableList<E> extends BaseObservableList<E>:
> *
> 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 behavior.

This part looks good.


More information about the openjfx-dev mailing list