Package org.eclipse.core.databinding.observable.list

# Class ObservableList<E>

java.lang.Object
org.eclipse.core.databinding.observable.AbstractObservable
org.eclipse.core.databinding.observable.list.ObservableList<E>

Type Parameters:
  `E` - the type of the elements in this list

All Implemented Interfaces:
  `Iterable<E>`, `Collection<E>`, `List<E>`, `IObservable`, `IObservableCollection<E>`, `IObservableList<E>`

Direct Known Subclasses:
  `WritableList`

public abstract class ObservableList<E> extends AbstractObservable implements IObservableList<E>
Abstract implementation of `IObservableList`, based on an underlying regular list.

This class is thread safe. All state accessing methods must be invoked from the `current realm`. Methods for adding and removing listeners may be invoked from any thread.

Since:
  1.0

## Field Summary

Fields
Modifier and Type
Field
Description
`protected List<E>`
`wrappedList`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`ObservableList(List<E> wrappedList, Object elementType)`
`protected`
`ObservableList(Realm realm, List<E> wrappedList, Object elementType)`

## Method Summary

Modifier and Type
Method
Description
`void`
`add(int index, E element)`
`boolean`
`add(E o)`
`boolean`
`addAll(int index, Collection<? extends E> c)`
`boolean`
`addAll(Collection<? extends E> c)`
`void`
`addListChangeListener(IListChangeListener<? super E> listener)`
Adds the given list change listener to the list of list change listeners.
`protected void`
`addListener(Object listenerType, IObservablesListener listener)`
`void`
`clear()`
`protected Object`
`clone()`
`boolean`
`contains(Object o)`
`boolean`
`containsAll(Collection<?> c)`
`boolean`
`equals(Object o)`
`protected void`
`fireChange()`
`protected void`
`fireEvent(ObservableEvent event)`
`protected void`
`fireListChange(ListDiff<E> diff)`
`protected void`
`firstListenerAdded()`
`E`
`get(int index)`
`Object`
`getElementType()`
Returns the element type of this observable collection, or `null` if this observable collection is untyped.
`Realm`
`getRealm()`
`protected void`
`getterCalled()`
`int`
`hashCode()`
`protected boolean`
`hasListeners()`
`int`
`indexOf(Object o)`
`boolean`
`isEmpty()`
`boolean`
`isStale()`
Returns the stale state.
`Iterator<E>`
`iterator()`
`int`
`lastIndexOf(Object o)`
`protected void`
`lastListenerRemoved()`
`ListIterator<E>`
`listIterator()`
`ListIterator<E>`
`listIterator(int index)`
`E`
`move(int oldIndex, int newIndex)`
Moves the element located at `oldIndex` to `newIndex`.
`E`
`remove(int index)`
`boolean`
`remove(Object o)`
`boolean`
`removeAll(Collection<?> c)`
`void`
`removeListChangeListener(IListChangeListener<? super E> listener)`
Removes the given list change listener from the list of list change listeners.
`protected void`
`removeListener(Object listenerType, IObservablesListener listener)`
`boolean`
`retainAll(Collection<?> c)`
`E`
`set(int index, E element)`
`void`
`setStale(boolean stale)`
Sets the stale state.
`int`
`size()`
`List<E>`
`subList(int fromIndex, int toIndex)`
`Object[]`
`toArray()`
`<T> T[]`
`toArray(T[] a)`
`String`
`toString()`
`protected void`
`updateWrappedList(List<E> newList)`

### Methods inherited from class org.eclipse.core.databinding.observable.AbstractObservable

`addChangeListener, addDisposeListener, addStaleListener, checkRealm, dispose, fireStale, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Collection

`parallelStream, removeIf, stream, toArray`

### Methods inherited from interface org.eclipse.core.databinding.observable.IObservable

`addChangeListener, addDisposeListener, addStaleListener, dispose, getRealm, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener`

### Methods inherited from interface java.lang.Iterable

`forEach`

### Methods inherited from interface java.util.List

`replaceAll, sort, spliterator`

## Field Details

### wrappedList

protected List<E> wrappedList

## Constructor Details

### ObservableList

protected ObservableList(List<E> wrappedList, Object elementType)

### ObservableList

protected ObservableList(Realm realm, List<E> wrappedList, Object elementType)

## Method Details

### addListChangeListener

public void addListChangeListener(IListChangeListener<? super E> listener)
Description copied from interface: `IObservableList`
Adds the given list change listener to the list of list change listeners.

Specified by:
  `addListChangeListener` in interface `IObservableList<E>`
Parameters:
  `listener` - the change listener to add; not `null`

### removeListChangeListener

public void removeListChangeListener(IListChangeListener<? super E> listener)
Description copied from interface: `IObservableList`
Removes the given list change listener from the list of list change listeners. Has no effect if the given listener is not registered as a list change listener.

Specified by:
  `removeListChangeListener` in interface `IObservableList<E>`
Parameters:
  `listener` - the change listener to remove; not `null`

### fireListChange

protected void fireListChange(ListDiff<E> diff)

### contains

public boolean contains(Object o)

Specified by:
  `contains` in interface `Collection<E>`
Specified by:
  `contains` in interface `IObservableList<E>`
Specified by:
  `contains` in interface `List<E>`

### containsAll

public boolean containsAll(Collection<?> c)

Specified by:
  `containsAll` in interface `Collection<E>`
Specified by:
  `containsAll` in interface `IObservableList<E>`
Specified by:
  `containsAll` in interface `List<E>`

### equals

public boolean equals(Object o)

Specified by:
  `equals` in interface `Collection<E>`
Specified by:
  `equals` in interface `IObservableList<E>`
Specified by:
  `equals` in interface `List<E>`
Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Specified by:
  `hashCode` in interface `Collection<E>`
Specified by:
  `hashCode` in interface `IObservableList<E>`
Specified by:
  `hashCode` in interface `List<E>`
Overrides:
  `hashCode` in class `Object`

### isEmpty

public boolean isEmpty()

Specified by:
  `isEmpty` in interface `Collection<E>`
Specified by:
  `isEmpty` in interface `IObservableList<E>`
Specified by:
  `isEmpty` in interface `List<E>`

### iterator

public Iterator<E> iterator()

Specified by:
  `iterator` in interface `Collection<E>`
Specified by:
  `iterator` in interface `IObservableList<E>`
Specified by:
  `iterator` in interface `Iterable<E>`
Specified by:
  `iterator` in interface `List<E>`

### size

public int size()

Specified by:
  `size` in interface `Collection<E>`
Specified by:
  `size` in interface `IObservableList<E>`
Specified by:
  `size` in interface `List<E>`

### toArray

public Object[] toArray()

Specified by:
  `toArray` in interface `Collection<E>`
Specified by:
  `toArray` in interface `IObservableList<E>`
Specified by:
  `toArray` in interface `List<E>`

### toArray

public <T> T[] toArray(T[] a)

Specified by:
  `toArray` in interface `Collection<E>`
Specified by:
  `toArray` in interface `IObservableList<E>`
Specified by:
  `toArray` in interface `List<E>`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### get

public E get(int index)

Specified by:
  `get` in interface `IObservableList<E>`
Specified by:
  `get` in interface `List<E>`
TrackedGetter

### indexOf

public int indexOf(Object o)

Specified by:
  `indexOf` in interface `IObservableList<E>`
Specified by:
  `indexOf` in interface `List<E>`
TrackedGetter

### lastIndexOf

public int lastIndexOf(Object o)

Specified by:
  `lastIndexOf` in interface `IObservableList<E>`
Specified by:
  `lastIndexOf` in interface `List<E>`
TrackedGetter

### listIterator

public ListIterator<E> listIterator()

Specified by:
  `listIterator` in interface `IObservableList<E>`
Specified by:
  `listIterator` in interface `List<E>`
TrackedGetter

### listIterator

public ListIterator<E> listIterator(int index)

Specified by:
  `listIterator` in interface `IObservableList<E>`
Specified by:
  `listIterator` in interface `List<E>`
TrackedGetter

### subList

public List<E> subList(int fromIndex, int toIndex)

Specified by:
  `subList` in interface `IObservableList<E>`
Specified by:
  `subList` in interface `List<E>`

### getterCalled

protected void getterCalled()

### set

public E set(int index, E element)

Specified by:
  `set` in interface `IObservableList<E>`
Specified by:
  `set` in interface `List<E>`

### move

public E move(int oldIndex, int newIndex)
Moves the element located at `oldIndex` to `newIndex`. This method is equivalent to calling `add(newIndex, remove(oldIndex))`.

Subclasses should override this method to deliver list change notification for the remove and add operations in the same ListChangeEvent, as this allows `ListDiff.accept(ListDiffVisitor)` to recognize the operation as a move.

Specified by:
  `move` in interface `IObservableList<E>`
Parameters:
  `oldIndex` - the element's position before the move. Must be within the range `0 <= oldIndex < size()`.
  `newIndex` - the element's position after the move. Must be within the range `0 <= newIndex < size()`.
Returns:
  the element that was moved.
Throws:
  `IndexOutOfBoundsException` - if either argument is out of range ( `0 <= index < size()`).
Since:
  1.1
See Also:
  - `ListDiffVisitor.handleMove(int, int, Object)`
  - `ListDiff.accept(ListDiffVisitor)`

### remove

public E remove(int index)

Specified by:
  `remove` in interface `IObservableList<E>`
Specified by:
  `remove` in interface `List<E>`

### add

public boolean add(E o)

Specified by:
  `add` in interface `Collection<E>`
Specified by:
  `add` in interface `IObservableList<E>`
Specified by:
  `add` in interface `List<E>`

### add

public void add(int index, E element)

Specified by:
  `add` in interface `List<E>`

### addAll

public boolean addAll(Collection<? extends E> c)

Specified by:
  `addAll` in interface `Collection<E>`
Specified by:
  `addAll` in interface `IObservableList<E>`
Specified by:
  `addAll` in interface `List<E>`

### addAll

public boolean addAll(int index, Collection<? extends E> c)

Specified by:
  `addAll` in interface `IObservableList<E>`
Specified by:
  `addAll` in interface `List<E>`

### remove

public boolean remove(Object o)

Specified by:
  `remove` in interface `Collection<E>`
Specified by:
  `remove` in interface `IObservableList<E>`
Specified by:
  `remove` in interface `List<E>`

### removeAll

public boolean removeAll(Collection<?> c)

Specified by:
  `removeAll` in interface `Collection<E>`
Specified by:
  `removeAll` in interface `IObservableList<E>`
Specified by:
  `removeAll` in interface `List<E>`

### retainAll

public boolean retainAll(Collection<?> c)

Specified by:
  `retainAll` in interface `Collection<E>`
Specified by:
  `retainAll` in interface `IObservableList<E>`
Specified by:
  `retainAll` in interface `List<E>`

### clear

public void clear()

Specified by:
  `clear` in interface `Collection<E>`
Specified by:
  `clear` in interface `List<E>`

### isStale

public boolean isStale()
Returns the stale state. Must be invoked from the current realm.

Specified by:
  `isStale` in interface `IObservable`
Returns:
  stale state

### setStale

public void setStale(boolean stale)
Sets the stale state. Must be invoked from the current realm.

Parameters:
  `stale` - The stale state to list. This will fire a stale event if the given boolean is true and this observable list was not already stale.

### fireChange

protected void fireChange()

Overrides:
  `fireChange` in class `AbstractObservable`

### getElementType

public Object getElementType()
Description copied from interface: `IObservableCollection`
Returns the element type of this observable collection, or `null` if this observable collection is untyped.

Specified by:
  `getElementType` in interface `IObservableCollection<E>`
Specified by:
  `getElementType` in interface `IObservableList<E>`
Returns:
  the type of the elements or `null` if untyped

### updateWrappedList

protected void updateWrappedList(List<E> newList)

### addListener

protected void addListener(Object listenerType, IObservablesListener listener)

Parameters:
  `listenerType` - arbitrary object to identify a type of the listener
  `listener` - the listener to add; not `null`

### removeListener

protected void removeListener(Object listenerType, IObservablesListener listener)

Parameters:
  `listenerType` - arbitrary object to identify a type of the listener
  `listener` - the listener to remove; not `null`

### hasListeners

protected boolean hasListeners()

### fireEvent

protected void fireEvent(ObservableEvent event)

### firstListenerAdded

protected void firstListenerAdded()

### lastListenerRemoved

protected void lastListenerRemoved()

### getRealm

public Realm getRealm()

Returns:
  Returns the realm.

### clone

protected Object clone() throws CloneNotSupportedException

Overrides:
  `clone` in class `Object`
Throws:
  `CloneNotSupportedException`