T
- The type of the elements contained in this collection.public class ObservableCollection<T> extends Object implements IObservableCollection<T>, ICollection<T>
IObservableCollection
that is backed by an ordinary Collection
.EMPTY
Constructor and Description |
---|
ObservableCollection()
Creates a new instance using a
ArrayList as the backing store. |
ObservableCollection(Collection<T> items)
Creates a new instance using a provided collection as the backing store.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(T item)
Adds the item the the collection and triggers the
ItemAdded event. |
void |
addItemAddedListener(IEventHandler<ItemEventArgs<T>> itemAddedEvent)
Adds the given listener for the
ItemAdded event that occurs when an item has been added to this collection. |
void |
addItemChangedListener(IEventHandler<ItemEventArgs<T>> itemChangedEvent)
Adds the given listener for the
ItemChanged event that occurs when an item has been changed inside this
collection. |
void |
addItemRemovedListener(IEventHandler<ItemEventArgs<T>> itemRemovedEvent)
Adds the given listener for the
ItemRemoved event that occurs when an item has been removed from this
collection. |
void |
clear()
Clears this collection, triggering an
ItemRemoved event for each element
removed. |
boolean |
contains(Object item)
Checks for containment of the item in this collection.
|
void |
copyTo(T[] array,
int arrayIndex)
Copies the items to the given array.
|
IEnumerator<T> |
enumerator()
Returns an enumerator over the elements in this collection.
|
Collection<T> |
getItems()
Returns the collection used internally as the backing store.
|
protected void |
onItemAdded(T item)
Callback method that will trigger the
ItemAdded event. |
protected void |
onItemChanged(T item)
Callback method that will trigger the
ItemChanged event. |
protected void |
onItemRemoved(T item)
Callback method that will trigger the
ItemRemoved event. |
Stream<T> |
parallelStream()
Returns a parallel
Stream using the elements of this enumerable. |
void |
publishItemChanged(T item)
Method that may be called by client code to trigger an
ItemChanged
event. |
boolean |
remove(Object item)
Tries to remove the item from the collection and triggers the
ItemRemoved
event. |
void |
removeItemAddedListener(IEventHandler<ItemEventArgs<T>> itemAddedEvent)
Removes the given listener for the
ItemAdded event that occurs when an item has been added to this collection. |
void |
removeItemChangedListener(IEventHandler<ItemEventArgs<T>> itemChangedEvent)
Removes the given listener for the
ItemChanged event that occurs when an item has been changed inside this
collection. |
void |
removeItemRemovedListener(IEventHandler<ItemEventArgs<T>> itemRemovedEvent)
Removes the given listener for the
ItemRemoved event that occurs when an item has been removed from this
collection. |
int |
size()
Returns the number of elements in this collection.
|
Stream<T> |
stream()
Returns a sequential
Stream using the elements of this enumerable. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAll, containsAll, isEmpty, iterator, removeAll, retainAll, toArray, toArray
concat, concat, create, create
equals, hashCode, removeIf, spliterator
public ObservableCollection()
ArrayList
as the backing store.public ObservableCollection(Collection<T> items)
public boolean add(T item)
ItemAdded
event.
This implementation calls the onItemAdded(Object)
method.
add
in interface Collection<T>
item
- The item to add to the collection.public final void addItemAddedListener(IEventHandler<ItemEventArgs<T>> itemAddedEvent)
ItemAdded
event that occurs when an item has been added to this collection.addItemAddedListener
in interface IObservableCollection<T>
itemAddedEvent
- The listener to add.removeItemAddedListener(IEventHandler)
public final void addItemChangedListener(IEventHandler<ItemEventArgs<T>> itemChangedEvent)
ItemChanged
event that occurs when an item has been changed inside this
collection.addItemChangedListener
in interface IObservableCollection<T>
itemChangedEvent
- The listener to add.removeItemChangedListener(IEventHandler)
public final void addItemRemovedListener(IEventHandler<ItemEventArgs<T>> itemRemovedEvent)
ItemRemoved
event that occurs when an item has been removed from this
collection.addItemRemovedListener
in interface IObservableCollection<T>
itemRemovedEvent
- The listener to add.removeItemRemovedListener(IEventHandler)
public void clear()
ItemRemoved
event for each element
removed.clear
in interface Collection<T>
onItemRemoved(Object)
public boolean contains(Object item)
contains
in interface Collection<T>
item
- The item to check.public final void copyTo(T[] array, int arrayIndex)
public final IEnumerator<T> enumerator()
enumerator
in interface IEnumerable<T>
IEnumerator
.public final Collection<T> getItems()
Normally code should not use this method to gain access to the collection in order to modify it.
protected void onItemAdded(T item)
ItemAdded
event.item
- The item that has just been added to the collection.protected void onItemChanged(T item)
ItemChanged
event.item
- The item that has changed.protected void onItemRemoved(T item)
ItemRemoved
event.item
- The item that has just been removed from the collection.public Stream<T> parallelStream()
ICollection
Stream
using the elements of this enumerable.parallelStream
in interface ICollection<T>
parallelStream
in interface IEnumerable<T>
parallelStream
in interface Collection<T>
Stream
using the elements of this enumerable.public final void publishItemChanged(T item)
ItemChanged
event.item
- The item to trigger the change event for.onItemChanged(Object)
public boolean remove(Object item)
ItemRemoved
event.remove
in interface ICollection<T>
remove
in interface Collection<T>
item
- The item to remove.onItemRemoved(Object)
public final void removeItemAddedListener(IEventHandler<ItemEventArgs<T>> itemAddedEvent)
ItemAdded
event that occurs when an item has been added to this collection.removeItemAddedListener
in interface IObservableCollection<T>
itemAddedEvent
- The listener to remove.addItemAddedListener(IEventHandler)
public final void removeItemChangedListener(IEventHandler<ItemEventArgs<T>> itemChangedEvent)
ItemChanged
event that occurs when an item has been changed inside this
collection.removeItemChangedListener
in interface IObservableCollection<T>
itemChangedEvent
- The listener to remove.addItemChangedListener(IEventHandler)
public final void removeItemRemovedListener(IEventHandler<ItemEventArgs<T>> itemRemovedEvent)
ItemRemoved
event that occurs when an item has been removed from this
collection.removeItemRemovedListener
in interface IObservableCollection<T>
itemRemovedEvent
- The listener to remove.addItemRemovedListener(IEventHandler)
public final int size()
size
in interface Collection<T>
public Stream<T> stream()
ICollection
Stream
using the elements of this enumerable.stream
in interface ICollection<T>
stream
in interface IEnumerable<T>
stream
in interface Collection<T>
Stream
using the elements of this enumerable.