Class NaiveTxnStack<E>

java.lang.Object
org.multiverse.collections.AbstractTxnCollection<E>
org.multiverse.collections.NaiveTxnStack<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, TxnCollection<E>, TxnIterable<E>, TxnStack<E>

public final class NaiveTxnStack<E> extends AbstractTxnCollection<E> implements TxnStack<E>
  • Field Details

  • Constructor Details

    • NaiveTxnStack

      public NaiveTxnStack(Stm stm)
    • NaiveTxnStack

      public NaiveTxnStack(Stm stm, int capacity)
  • Method Details

    • size

      public int size(Txn tx)
      Description copied from interface: TxnCollection
      Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
      Specified by:
      size in interface TxnCollection<E>
      Parameters:
      tx - the transaction used for this operation.
      Returns:
      the number of elements in this collection
    • getCapacity

      public int getCapacity()
      Specified by:
      getCapacity in interface TxnStack<E>
    • clear

      public void clear(Txn tx)
      Description copied from interface: TxnCollection
      Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.
      Specified by:
      clear in interface TxnCollection<E>
      Parameters:
      tx - the transaction used for this operation.
    • offer

      public boolean offer(E item)
      Specified by:
      offer in interface TxnStack<E>
    • offer

      public boolean offer(Txn tx, E item)
      Specified by:
      offer in interface TxnStack<E>
    • poll

      public E poll()
      Specified by:
      poll in interface TxnStack<E>
    • poll

      public E poll(Txn tx)
      Specified by:
      poll in interface TxnStack<E>
    • peek

      public E peek()
      Specified by:
      peek in interface TxnStack<E>
    • peek

      public E peek(Txn tx)
      Specified by:
      peek in interface TxnStack<E>
    • push

      public void push(E item)
      Specified by:
      push in interface TxnStack<E>
    • push

      public void push(Txn tx, E item)
      Specified by:
      push in interface TxnStack<E>
    • pop

      public E pop()
      Specified by:
      pop in interface TxnStack<E>
    • pop

      public E pop(Txn tx)
      Specified by:
      pop in interface TxnStack<E>
    • add

      public boolean add(Txn tx, E e)
      Description copied from interface: TxnCollection
      Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

      Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

      If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

      Specified by:
      add in interface TxnCollection<E>
      Parameters:
      tx - the transaction used for this operation.
      e - element whose presence in this collection is to be ensured
      Returns:
      true if this collection changed as a result of the call
    • iterator

      public TxnIterator<E> iterator(Txn tx)
      Description copied from interface: TxnIterable
      Returns an iterator over a set of elements of type T.
      Specified by:
      iterator in interface TxnIterable<E>
      Parameters:
      tx - the Txn used for this Operation.
      Returns:
      an Iterator.
    • contains

      public boolean contains(Txn tx, Object o)
      Description copied from interface: TxnCollection
      Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
      Specified by:
      contains in interface TxnCollection<E>
      Parameters:
      tx - the transaction used for this operation.
      o - element whose presence in this collection is to be tested
      Returns:
      true if this collection contains the specified element
    • remove

      public boolean remove(Txn tx, Object o)
      Description copied from interface: TxnCollection
      Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).
      Specified by:
      remove in interface TxnCollection<E>
      Parameters:
      tx - the transaction used for this operation.
      o - element to be removed from this collection, if present
      Returns:
      true if an element was removed as a result of this call
    • toString

      public String toString(Txn tx)
      Specified by:
      toString in interface TxnCollection<E>