Class AbstractSmartCollection<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- net.automatalib.common.smartcollection.AbstractSmartCollection<E>
-
- Type Parameters:
E- element class.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,SmartCollection<E>
- Direct Known Subclasses:
AbstractLinkedList,BackedGeneralPriorityQueue,BinaryHeap,UnorderedCollection
public abstract class AbstractSmartCollection<E> extends AbstractCollection<E> implements SmartCollection<E>
This class eases the implementation of theSmartCollectioninterface. It is comparable toAbstractCollectionfrom 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 Summary
Constructors Constructor Description AbstractSmartCollection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)voidaddAll(Iterable<? extends E> iterable)Adds all elements from a given iterable.<T extends E>
voidaddAll(T[] array)Adds all elements from the specified array.Echoose()Retrieves an arbitrary element from the collection.ElementReferencechooseRef()Retrieves the reference to an arbitrary element from the collection.voiddeepClear()Thoroughly clears the collection, fixing all issues that may have been caused by a call of the aboveSmartCollection.quickClear().@Nullable ElementReferencefind(@Nullable Object element)Retrieves the reference for a given element.Iterator<E>iterator()voidquickClear()Quickly clears this collection.Iterable<ElementReference>references()This is a method provided for convenience, which allows iterating over the element references using a foreach-stylefor-loop.booleanremove(@Nullable Object element)This function is deprecated and should not be used, in favor of the removal by referenceSmartCollection.remove(ElementReference).-
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, removeAll, retainAll, size, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
-
Methods inherited from interface net.automatalib.common.smartcollection.SmartCollection
get, referencedAdd, referenceIterator, remove, replace
-
-
-
-
Method Detail
-
choose
public E choose()
Description copied from interface:SmartCollectionRetrieves an arbitrary element from the collection.- Specified by:
choosein interfaceSmartCollection<E>- Returns:
- an arbitrary element from the collection
-
chooseRef
public ElementReference chooseRef()
Description copied from interface:SmartCollectionRetrieves the reference to an arbitrary element from the collection. If the collection is empty, aNoSuchElementExceptionis thrown.- Specified by:
chooseRefin interfaceSmartCollection<E>- Returns:
- the reference to an arbitrary element in the collection
-
references
public Iterable<ElementReference> references()
Description copied from interface:SmartCollectionThis is a method provided for convenience, which allows iterating over the element references using a foreach-stylefor-loop.- Specified by:
referencesin interfaceSmartCollection<E>- Returns:
- an
Iterablewith the aboveSmartCollection.referenceIterator()as its iterator.
-
addAll
public void addAll(Iterable<? extends E> iterable)
Description copied from interface:SmartCollectionAdds all elements from a given iterable. Note that this may be inefficient, compared to adding aCollection, because the number of elements to be added is not known a priori.- Specified by:
addAllin interfaceSmartCollection<E>- Parameters:
iterable- the iterable of elements to add.
-
addAll
public <T extends E> void addAll(T[] array)
Description copied from interface:SmartCollectionAdds all elements from the specified array.- Specified by:
addAllin interfaceSmartCollection<E>- Type Parameters:
T- array element class, may be a subclass ofE.- Parameters:
array- the array of elements to be added.
-
find
public @Nullable ElementReference find(@Nullable Object element)
Description copied from interface:SmartCollectionRetrieves the reference for a given element. If the element is not contained in the collection,nullis returned.- Specified by:
findin interfaceSmartCollection<E>- Parameters:
element- the element to search for.- Returns:
- the reference to this element, or
null.
-
quickClear
public void quickClear()
Description copied from interface:SmartCollectionQuickly clears this collection. This method is supposed to perform the minimum amount of effort such that this collection is emptied, disregarding all other side effects such as referencing or garbage collection issues.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 methodSmartCollection.deepClear()below.- Specified by:
quickClearin interfaceSmartCollection<E>
-
deepClear
public void deepClear()
Description copied from interface:SmartCollectionThoroughly clears the collection, fixing all issues that may have been caused by a call of the aboveSmartCollection.quickClear().- Specified by:
deepClearin interfaceSmartCollection<E>
-
iterator
public Iterator<E> iterator()
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-
add
public boolean add(E e)
- Specified by:
addin interfaceCollection<E>- Overrides:
addin classAbstractCollection<E>
-
remove
public boolean remove(@Nullable Object element)
Description copied from interface:SmartCollectionThis function is deprecated and should not be used, in favor of the removal by referenceSmartCollection.remove(ElementReference).- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSmartCollection<E>- Overrides:
removein classAbstractCollection<E>
-
-