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 E choose()
SmartCollectionNoSuchElementException
is thrownchoose in interface SmartCollection<E>public ElementReference chooseRef()
SmartCollectionNoSuchElementException is thrown.chooseRef in interface SmartCollection<E>public Iterable<ElementReference> references()
SmartCollectionfor-loop.references in interface SmartCollection<E>Iterable with the above SmartCollection.referenceIterator() as its iterator.public 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 ElementReference find(Object element)
SmartCollectionnull
is returned.find in interface SmartCollection<E>element - the element to search for.null.public void quickClear()
SmartCollection
Depending on the implementation, this may be just the same as Collection.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>public void deepClear()
SmartCollectionSmartCollection.quickClear().deepClear in interface SmartCollection<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in class AbstractCollection<E>public boolean add(E e)
add in interface Collection<E>add in class AbstractCollection<E>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)Copyright © 2018. All rights reserved.