Package org.multiverse.api.collections

## Interface TxnCollection<E>

- Type Parameters:
    `E` -
  All Superinterfaces:
    `Collection<E>`, `Iterable<E>`, `TxnIterable<E>`
  All Known Subinterfaces:
    `TxnDeque<E>`, `TxnList<E>`, `TxnQueue<E>`, `TxnSet<E>`, `TxnStack<E>`
  All Known Implementing Classes:
    `AbstractTxnCollection`, `NaiveTxnHashSet`, `NaiveTxnLinkedList`, `NaiveTxnStack`

      public interface TxnCollection<E>
      extends TxnIterable<E>, Collection<E>

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `add​(Txn txn, E e)` | Ensures that this collection contains the specified element (optional operation).
    `boolean` | `addAll​(TxnCollection<? extends E> c)` | Adds all of the elements in the specified collection to this collection (optional operation).
    `boolean` | `addAll​(Txn txn, Collection<? extends E> c)` | Adds all of the elements in the specified collection to this collection (optional operation).
    `boolean` | `addAll​(Txn txn, TxnCollection<? extends E> c)` | Adds all of the elements in the specified collection to this collection (optional operation).
    `void` | `clear​(Txn txn)` | Removes all of the elements from this collection (optional operation).
    `boolean` | `contains​(Txn txn, Object o)` | Returns `true` if this collection contains the specified element.
    `boolean` | `containsAll​(Txn txn, Collection<?> c)` | Returns `true` if this collection contains all of the elements in the specified collection.
    `Stm` | `getStm()` | Returns the STM that manages this TxnCollection.
    `boolean` | `isEmpty​(Txn txn)` | Returns `true` if this collection contains no elements.
    `boolean` | `remove​(Txn txn, Object o)` | Removes a single instance of the specified element from this collection, if it is present (optional operation).
    `int` | `size​(Txn txn)` | Returns the number of elements in this collection.
    `String` | `toString​(Txn txn)` |

    - ### Methods inherited from interface java.util.Collection

      `add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

    - ### Methods inherited from interface org.multiverse.api.collections.TxnIterable

      `iterator, iterator`

- - ### Method Detail

    - #### getStm

          Stm getStm()

      Returns the STM that manages this TxnCollection. Returned value will never be null.
      Returns:
        the STM that manages this TxnCollection.

    - #### isEmpty

          boolean isEmpty​(Txn txn)

      Returns `true` if this collection contains no elements.
      Parameters:
        `txn` - the transaction used for this operation.
      Returns:
        `true` if this collection contains no elements

    - #### size

          int size​(Txn txn)

      Returns the number of elements in this collection. If this collection contains more than `Integer.MAX_VALUE` elements, returns `Integer.MAX_VALUE`.
      Parameters:
        `txn` - the transaction used for this operation.
      Returns:
        the number of elements in this collection

    - #### contains

          boolean contains​(Txn txn,
                           Object o)

      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))`.
      Parameters:
        `txn` - 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
      Throws:
        `ClassCastException` - if the type of the specified element is incompatible with this collection (optional)
        `NullPointerException` - if the specified element is null and this collection does not permit null elements (optional)

    - #### containsAll

          boolean containsAll​(Txn txn,
                              Collection<?> c)

      Returns `true` if this collection contains all of the elements in the specified collection.
      Parameters:
        `txn` - the transaction used for this operation.
        `c` - collection to be checked for containment in this collection
      Returns:
        `true` if this collection contains all of the elements in the specified collection
      Throws:
        `ClassCastException` - if the types of one or more elements in the specified collection are incompatible with this collection (optional)
        `NullPointerException` - if the specified collection contains one or more null elements and this collection does not permit null elements (optional), or if the specified collection is null
      See Also:
        `Collection.contains(Object)`

    - #### remove

          boolean remove​(Txn txn,
                         Object o)

      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).
      Parameters:
        `txn` - 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
      Throws:
        `ClassCastException` - if the type of the specified element is incompatible with this collection (optional)
        `NullPointerException` - if the specified element is null and this collection does not permit null elements (optional)
        `UnsupportedOperationException` - if the `remove` operation is not supported by this collection

    - #### clear

          void clear​(Txn txn)

      Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.
      Parameters:
        `txn` - the transaction used for this operation.
      Throws:
        `UnsupportedOperationException` - if the `clear` operation is not supported by this collection

    - #### add

          boolean add​(Txn txn,
                      E e)

      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.
      Parameters:
        `txn` - 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
      Throws:
        `UnsupportedOperationException` - if the `add` operation is not supported by this collection
        `ClassCastException` - if the class of the specified element prevents it from being added to this collection
        `NullPointerException` - if the specified element is null and this collection does not permit null elements
        `IllegalArgumentException` - if some property of the element prevents it from being added to this collection
        `IllegalStateException` - if the element cannot be added at this time due to insertion restrictions

    - #### addAll

          boolean addAll​(Txn txn,
                         Collection<? extends E> c)

      Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
      Parameters:
        `txn` - the transaction used for this operation.
        `c` - collection containing elements to be added to this collection
      Returns:
        `true` if this collection changed as a result of the call
      Throws:
        `UnsupportedOperationException` - if the `addAll` operation is not supported by this collection
        `ClassCastException` - if the class of an element of the specified collection prevents it from being added to this collection
        `NullPointerException` - if the specified collection contains a null element and this collection does not permit null elements, or if the specified collection is null
        `IllegalArgumentException` - if some property of an element of the specified collection prevents it from being added to this collection
        `IllegalStateException` - if not all the elements can be added at this time due to insertion restrictions
      See Also:
        `Collection.add(Object)`

    - #### addAll

          boolean addAll​(TxnCollection<? extends E> c)

      Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
      Parameters:
        `c` - collection containing elements to be added to this collection
      Returns:
        `true` if this collection changed as a result of the call
      Throws:
        `UnsupportedOperationException` - if the `addAll` operation is not supported by this collection
        `ClassCastException` - if the class of an element of the specified collection prevents it from being added to this collection
        `NullPointerException` - if the specified collection contains a null element and this collection does not permit null elements, or if the specified collection is null
        `IllegalArgumentException` - if some property of an element of the specified collection prevents it from being added to this collection
        `IllegalStateException` - if not all the elements can be added at this time due to insertion restrictions
      See Also:
        `Collection.add(Object)`

    - #### addAll

          boolean addAll​(Txn txn,
                         TxnCollection<? extends E> c)

      Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
      Parameters:
        `c` - collection containing elements to be added to this collection
      Returns:
        `true` if this collection changed as a result of the call
      Throws:
        `UnsupportedOperationException` - if the `addAll` operation is not supported by this collection
        `ClassCastException` - if the class of an element of the specified collection prevents it from being added to this collection
        `NullPointerException` - if the specified collection contains a null element and this collection does not permit null elements, or if the specified collection is null
        `IllegalArgumentException` - if some property of an element of the specified collection prevents it from being added to this collection
        `IllegalStateException` - if not all the elements can be added at this time due to insertion restrictions
      See Also:
        `Collection.add(Object)`

    - #### toString

          String toString​(Txn txn)