Package com.yetnt.utils.collection
Class SetDeque<T>
java.lang.Object
java.util.AbstractCollection<T>
java.util.ArrayDeque<T>
com.yetnt.utils.collection.SetDeque<T>
- Type Parameters:
T- the type of elements held in this collection
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<T>,Collection<T>,Deque<T>,Queue<T>,SequencedCollection<T>
Structure with the behaviour of a
Set and a Deque.
This class extends ArrayDeque to provide a double-ended queue, but overrides
its insertion methods to enforce uniqueness of elements, similar to a Set.
From J3Engine
- Author:
- Lehlogonolo Poole
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSetDeque()Constructs an empty SetDeque.SetDeque(Collection<? extends T> c) Constructs a SetDeque containing the elements of the specified collection, with duplicates removed. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the specified element to the end of this deque, only if it is not already present in the deque.booleanaddAll(Collection<? extends T> c) Adds all the elements in the specified collection to the end of this deque, ignoring any duplicates.voidInserts the specified element at the front of this deque.voidInserts the specified element at the end of this deque.copy()Creates a shallow copy of thisSetDeque.Methods inherited from class java.util.ArrayDeque
clear, clone, contains, descendingIterator, element, forEach, getFirst, getLast, isEmpty, iterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, removeAll, removeFirst, removeFirstOccurrence, removeIf, removeLast, removeLastOccurrence, retainAll, size, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
containsAll, equals, hashCode, parallelStream, stream, toArray
-
Constructor Details
-
SetDeque
public SetDeque()Constructs an empty SetDeque. -
SetDeque
Constructs a SetDeque containing the elements of the specified collection, with duplicates removed.- Parameters:
c- the collection whose elements are to be placed into this deque
-
-
Method Details
-
add
Adds the specified element to the end of this deque, only if it is not already present in the deque. -
addAll
Adds all the elements in the specified collection to the end of this deque, ignoring any duplicates.- Specified by:
addAllin interfaceCollection<T>- Specified by:
addAllin interfaceDeque<T>- Overrides:
addAllin classArrayDeque<T>- Parameters:
c- collection containing elements to be added to this deque- Returns:
trueif this deque changed as a result of the call
-
addFirst
Inserts the specified element at the front of this deque.If the element already exists in the deque, it is first removed from its current position and then inserted at the front, effectively repositioning it.
- Specified by:
addFirstin interfaceDeque<T>- Specified by:
addFirstin interfaceSequencedCollection<T>- Overrides:
addFirstin classArrayDeque<T>- Parameters:
t- the element to add
-
addLast
Inserts the specified element at the end of this deque.If the element already exists in the deque, it is first removed from its current position and then inserted at the end, effectively repositioning it.
- Specified by:
addLastin interfaceDeque<T>- Specified by:
addLastin interfaceSequencedCollection<T>- Overrides:
addLastin classArrayDeque<T>- Parameters:
t- the element to add
-
copy
Creates a shallow copy of thisSetDeque.- Returns:
- a new
SetDequeinstance containing the same elements in the same order
-