/** * Creates a reactive list with the supplied underlying list implementation. */ public static <E> RList<E> create (List<E> impl) { return new RList<E>(impl); }
@Override public boolean addAll (int index, Collection<? extends E> elements) { checkMutate(); // Call add instead of calling _impl.addAll so if a listener throws an exception on // emission, we don't have elements added without a corresponding emission for (E elem : elements) { add(index++, elem); } return true; }
@Override public E remove (int index) { checkMutate(); E removed = _impl.remove(index); emitRemove(index, removed); return removed; }
@Override public E set (int index, E element) { checkMutate(); E removed = _impl.set(index, element); emitSet(index, element, removed); return removed; }
@Override public void add (int index, E element) { checkMutate(); _impl.add(index, element); emitAdd(index, element); }
/** * Creates a reactive list backed by an {@link ArrayList}. */ public static <E> RList<E> create () { return create(new ArrayList<E>()); }
/** * Connects the supplied listener to this list, such that it will be notified on adds and * removes. * @return a connection instance which can be used to cancel the connection. */ public Connection connect (Listener<? super E> listener) { return addConnection(listener); }
@Override public E remove (int index) { checkMutate(); E removed = _impl.remove(index); emitRemove(index, removed); return removed; }
@Override public E set (int index, E element) { checkMutate(); E removed = _impl.set(index, element); emitSet(index, element, removed); return removed; }
@Override public void add (int index, E element) { checkMutate(); _impl.add(index, element); emitAdd(index, element); }
/** * Creates a reactive list backed by an {@link ArrayList}. */ public static <E> RList<E> create () { return create(new ArrayList<E>()); }
/** * Connects the supplied listener to this list, such that it will be notified on adds and * removes. * @return a connection instance which can be used to cancel the connection. */ public Connection connect (Listener<? super E> listener) { return addConnection(listener); }
/** * Removes the supplied element from the list, forcing a notification to the listeners * regardless of whether the element was in the list or not. * @return true if the element was in the list and was removed, false if it was not. */ public boolean removeForce (E elem) { checkMutate(); int index = _impl.indexOf(elem); if (index >= 0) _impl.remove(index); emitRemove(index, elem); return (index >= 0); }
public void set (E elem) { checkMutate(); iiter.set(elem); emitSet(iiter.previousIndex(), elem, _current); _current = elem; } protected E _current; // the element targeted by remove or set
public void add (E elem) { checkMutate(); int index = iiter.nextIndex(); iiter.add(elem); emitAdd(index, elem); } public boolean hasNext () {