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>

public class SetDeque<T> extends ArrayDeque<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 Details

    • SetDeque

      public SetDeque()
      Constructs an empty SetDeque.
    • SetDeque

      public SetDeque(Collection<? extends T> c)
      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

      public boolean add(T t)
      Adds the specified element to the end of this deque, only if it is not already present in the deque.
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Deque<T>
      Specified by:
      add in interface Queue<T>
      Overrides:
      add in class ArrayDeque<T>
      Parameters:
      t - the element to add
      Returns:
      true if the element was added, false if the deque already contained the element
    • addAll

      public boolean addAll(Collection<? extends T> c)
      Adds all the elements in the specified collection to the end of this deque, ignoring any duplicates.
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Deque<T>
      Overrides:
      addAll in class ArrayDeque<T>
      Parameters:
      c - collection containing elements to be added to this deque
      Returns:
      true if this deque changed as a result of the call
    • addFirst

      public void addFirst(T t)
      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:
      addFirst in interface Deque<T>
      Specified by:
      addFirst in interface SequencedCollection<T>
      Overrides:
      addFirst in class ArrayDeque<T>
      Parameters:
      t - the element to add
    • addLast

      public void addLast(T t)
      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:
      addLast in interface Deque<T>
      Specified by:
      addLast in interface SequencedCollection<T>
      Overrides:
      addLast in class ArrayDeque<T>
      Parameters:
      t - the element to add
    • copy

      public SetDeque<T> copy()
      Creates a shallow copy of this SetDeque.
      Returns:
      a new SetDeque instance containing the same elements in the same order