public class MyArrayList<E> extends ArrayList<E> implements Observable
ArrayList
, which
notifies other objects (ListObserver) when it is modified.
Notifications are made using ListEvent objects.Modifier and Type | Field and Description |
---|---|
protected List<ListObserver> |
observers
The objects that monitor this list aka observers that the list will
notify when an event occurs.
|
modCount
Constructor and Description |
---|
MyArrayList() |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Appends an element to the list and notifies all its observers about this
event.
|
void |
addObserver(ListObserver o)
Registers an observer that will receive notifications about the
list's events.
|
protected void |
notifyObservers(ListEvent e)
Notifies all the ListObserver objects registered by this list.
|
E |
remove(int index)
Removes the element at the specified position in this list
ArrayList.remove(int)
and notifies
all the list's observers about this event. |
void |
removeObserver(ListObserver o)
Removes an observer.
|
E |
set(int index,
E element)
Replaces the element at the specified position in this list with the
specified element and notifies all the list's observers about this
event.
|
String |
toString() |
add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, removeRange, retainAll, size, subList, toArray, toArray, trimToSize
equals, hashCode
containsAll
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode
protected List<ListObserver> observers
public void addObserver(ListObserver o)
addObserver
in interface Observable
o
- the observerpublic void removeObserver(ListObserver o)
removeObserver
in interface Observable
o
- the observerpublic boolean add(E e)
add
in interface Collection<E>
add
in interface List<E>
add
in class ArrayList<E>
e
- element to be appended to this listCollection.add(E)
)public E set(int index, E element)
public E remove(int index)
ArrayList.remove(int)
and notifies
all the list's observers about this event.protected void notifyObservers(ListEvent e)
e
- the event that occurred on the listpublic String toString()
toString
in class AbstractCollection<E>