E - element class.public abstract class AbstractSmartCollection<E> extends AbstractCollection<E> implements SmartCollection<E>
SmartCollection
interface. It is comparable to AbstractCollection from the
Java Collections Framework.
A class extending this abstract class has to implement the following
methods:
- Collection.size()
- SmartCollection.get(ElementReference)
- SmartCollection.referenceIterator()
- SmartCollection.referencedAdd(Object)
- SmartCollection.remove(ElementReference)
- SmartCollection.replace(ElementReference, Object)| Constructor and Description |
|---|
AbstractSmartCollection() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e) |
void |
addAll(Iterable<? extends E> iterable)
Adds all elements from a given iterable.
|
<T extends E> |
addAll(T[] array)
Adds all elements from the specified array.
|
E |
choose()
Retrieves an arbitrary element from the collection.
|
ElementReference |
chooseRef()
Retrieves the reference to an arbitrary element from the collection.
|
void |
deepClear()
Thoroughly clears the collection, fixing all issues that may have been
caused by a call of the above
SmartCollection.quickClear(). |
ElementReference |
find(Object element)
Retrieves the reference for a given element.
|
Iterator<E> |
iterator() |
void |
quickClear()
Quickly clears this collection.
|
Iterable<ElementReference> |
references()
This is a method provided for convenience, which allows iterating
over the element references using a foreach-style
for-loop. |
boolean |
remove(Object element)
This function is deprecated and should not be used, in favor of
the removal by reference
SmartCollection.remove(ElementReference). |
addAll, clear, contains, containsAll, isEmpty, removeAll, retainAll, size, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitget, referencedAdd, referenceIterator, remove, replaceaddAll, clear, contains, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArraypublic void addAll(Iterable<? extends E> iterable)
SmartCollectionCollection, because the
number of elements to be added is not known a priori.addAll in interface SmartCollection<E>iterable - the iterable of elements to add.public <T extends E> void addAll(T[] array)
SmartCollectionaddAll in interface SmartCollection<E>T - array element class, may be a subclass of E.array - the array of elements to be added.public E choose()
SmartCollectionNoSuchElementException is thrownchoose in interface SmartCollection<E>public ElementReference chooseRef()
SmartCollectionNoSuchElementException
is thrown.chooseRef in interface SmartCollection<E>public boolean add(E e)
add in interface Collection<E>add in class AbstractCollection<E>public Iterable<ElementReference> references()
SmartCollectionfor-loop.references in interface SmartCollection<E>Iterable with the above SmartCollection.referenceIterator()
as its iterator.public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in class AbstractCollection<E>public ElementReference find(Object element)
SmartCollectionnull is returned.find in interface SmartCollection<E>element - the element to search for.null.public boolean remove(Object element)
SmartCollectionSmartCollection.remove(ElementReference).remove in interface Collection<E>remove in interface SmartCollection<E>remove in class AbstractCollection<E>Collection.remove(Object)public void deepClear()
SmartCollectionSmartCollection.quickClear().deepClear in interface SmartCollection<E>public void quickClear()
SmartCollectionCollection.clear(). However, this could also have side-effects
like hampering the garbage collection or such.
After calling this method, even a call of the normal
Collection.clear() is not guaranteed to fix all these issues.
This can only be achieved by the method SmartCollection.deepClear() below.quickClear in interface SmartCollection<E>Copyright © 2015. All Rights Reserved.