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 theSmartCollection
interface. It is comparable toAbstractCollection
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 Summary
Constructors Constructor Description AbstractSmartCollection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
void
addAll(Iterable<? extends E> iterable)
Adds all elements from a given iterable.<T extends E>
voidaddAll(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 aboveSmartCollection.quickClear()
.@Nullable ElementReference
find(@Nullable 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-stylefor
-loop.boolean
remove(@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:SmartCollection
Retrieves an arbitrary element from the collection.- Specified by:
choose
in interfaceSmartCollection<E>
- Returns:
- an arbitrary element from the collection
-
chooseRef
public ElementReference chooseRef()
Description copied from interface:SmartCollection
Retrieves the reference to an arbitrary element from the collection. If the collection is empty, aNoSuchElementException
is thrown.- Specified by:
chooseRef
in interfaceSmartCollection<E>
- Returns:
- the reference to an arbitrary element in the collection
-
references
public Iterable<ElementReference> references()
Description copied from interface:SmartCollection
This is a method provided for convenience, which allows iterating over the element references using a foreach-stylefor
-loop.- Specified by:
references
in interfaceSmartCollection<E>
- Returns:
- an
Iterable
with the aboveSmartCollection.referenceIterator()
as its iterator.
-
addAll
public void addAll(Iterable<? extends E> iterable)
Description copied from interface:SmartCollection
Adds 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:
addAll
in interfaceSmartCollection<E>
- Parameters:
iterable
- the iterable of elements to add.
-
addAll
public <T extends E> void addAll(T[] array)
Description copied from interface:SmartCollection
Adds all elements from the specified array.- Specified by:
addAll
in 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:SmartCollection
Retrieves the reference for a given element. If the element is not contained in the collection,null
is returned.- Specified by:
find
in 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:SmartCollection
Quickly 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:
quickClear
in interfaceSmartCollection<E>
-
deepClear
public void deepClear()
Description copied from interface:SmartCollection
Thoroughly clears the collection, fixing all issues that may have been caused by a call of the aboveSmartCollection.quickClear()
.- Specified by:
deepClear
in interfaceSmartCollection<E>
-
iterator
public Iterator<E> iterator()
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-
add
public boolean add(E e)
- Specified by:
add
in interfaceCollection<E>
- Overrides:
add
in classAbstractCollection<E>
-
remove
public boolean remove(@Nullable Object element)
Description copied from interface:SmartCollection
This function is deprecated and should not be used, in favor of the removal by referenceSmartCollection.remove(ElementReference)
.- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSmartCollection<E>
- Overrides:
remove
in classAbstractCollection<E>
-
-