Package de.learnlib.filter.reuse.tree
Class BoundedDeque<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- de.learnlib.filter.reuse.tree.BoundedDeque<E>
-
- Type Parameters:
E- element type
- All Implemented Interfaces:
Iterable<E>,Collection<E>
public class BoundedDeque<E> extends AbstractCollection<E>
A generic deque-derived container which transparently acts either as a stack or a queue, and optionally a capacity restriction with a configurable policy which element is evicted (or reject) if the maximum capacity is reached.Note: Like
ArrayDeque, this deque implementation is not thread-safe. Concurrent access by multiple threads requires explicit synchronization.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBoundedDeque.AccessPolicyThe policy which determines in which order elements are accessed.static classBoundedDeque.EvictPolicyThe policy which determines in which order elements are removed if the maximum capacity is reached.
-
Constructor Summary
Constructors Constructor Description BoundedDeque(int capacity, BoundedDeque.AccessPolicy accessPolicy, BoundedDeque.EvictPolicy evictPolicy)Constructor.BoundedDeque(BoundedDeque.AccessPolicy accessPolicy)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()@Nullable Einsert(E element)Inserts an element into the deque, and returns the one that had to be evicted in case of a capacity violation.booleanisBounded()Retrieves whether capacity restriction is in effect.booleanisEmpty()Iterator<E>iterator()Epeek()Retrieves, but does not remove the top-most element, i.e., the element that is either the top of the stack or the head of the queue, depending on the configuredBoundedDeque.AccessPolicy.Eretrieve()Retrieves and remove the top-most element, i.e., the element that is either the top of the stack or the head of the queue, depending on the configuredBoundedDeque.AccessPolicy.intsize()-
Methods inherited from class java.util.AbstractCollection
add, addAll, contains, containsAll, remove, removeAll, retainAll, 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
equals, hashCode, parallelStream, removeIf, spliterator, stream
-
-
-
-
Constructor Detail
-
BoundedDeque
public BoundedDeque(BoundedDeque.AccessPolicy accessPolicy)
Constructor. Creates an unbounded deque with the given access policy.- Parameters:
accessPolicy- whether this deque acts as a stack or a queue
-
BoundedDeque
public BoundedDeque(int capacity, BoundedDeque.AccessPolicy accessPolicy, BoundedDeque.EvictPolicy evictPolicy)Constructor. Creates a possibly capacity-restricted deque with the given access policy.- Parameters:
capacity- the maximum capacity of this deque. A value less than or equal to 0 means unboundedaccessPolicy- whether this deque acts as a stack or a queueevictPolicy- which elements to remove if the maximum capacity is reached. If the capacity is unbounded, this parameter has no effect
-
-
Method Detail
-
insert
public @Nullable E insert(E element)
Inserts an element into the deque, and returns the one that had to be evicted in case of a capacity violation.- Parameters:
element- the element to insert- Returns:
- the evicted element,
nullif the maximum capacity has not been reached
-
retrieve
public E retrieve()
Retrieves and remove the top-most element, i.e., the element that is either the top of the stack or the head of the queue, depending on the configuredBoundedDeque.AccessPolicy.- Returns:
- the top-most element of the container
-
peek
public E peek()
Retrieves, but does not remove the top-most element, i.e., the element that is either the top of the stack or the head of the queue, depending on the configuredBoundedDeque.AccessPolicy.- Returns:
- the top-most element of the container
-
isBounded
public boolean isBounded()
Retrieves whether capacity restriction is in effect.- Returns:
trueif the capacity is restricted,falseotherwise
-
iterator
public Iterator<E> iterator()
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-
size
public int size()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>
-
-