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 class
BoundedDeque.AccessPolicy
The policy which determines in which order elements are accessed.static class
BoundedDeque.EvictPolicy
The 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 void
clear()
@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.boolean
isBounded()
Retrieves whether capacity restriction is in effect.boolean
isEmpty()
Iterator<E>
iterator()
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
.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
.int
size()
-
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,
null
if 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:
true
if the capacity is restricted,false
otherwise
-
iterator
public Iterator<E> iterator()
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
- Overrides:
clear
in classAbstractCollection<E>
-
-