Class SortedCopyOnWriteArray<T extends Comparable<T>>

java.lang.Object
com.comphenix.protocol.concurrency.SortedCopyOnWriteArray<T>
Type Parameters:
T - - type of the elements in the list.
All Implemented Interfaces:
Iterable<T>, Collection<T>

public class SortedCopyOnWriteArray<T extends Comparable<T>> extends Object implements Collection<T>
An implicitly sorted array list that preserves insertion order and maintains duplicates.
  • Constructor Details

    • SortedCopyOnWriteArray

      public SortedCopyOnWriteArray()
      Construct an empty sorted array.
    • SortedCopyOnWriteArray

      public SortedCopyOnWriteArray(Collection<T> wrapped)
      Create a sorted array from the given list. The elements will be automatically sorted.
      Parameters:
      wrapped - - the collection whose elements are to be placed into the list.
    • SortedCopyOnWriteArray

      public SortedCopyOnWriteArray(Collection<T> wrapped, boolean sort)
      Create a sorted array from the given list.
      Parameters:
      wrapped - - the collection whose elements are to be placed into the list.
      sort - - TRUE to automatically sort the collection, FALSE if it is already sorted.
  • Method Details

    • add

      public boolean add(T value)
      Inserts the given element in the proper location.
      Specified by:
      add in interface Collection<T extends Comparable<T>>
      Parameters:
      value - - element to insert.
    • addAll

      public boolean addAll(Collection<? extends T> values)
      Specified by:
      addAll in interface Collection<T extends Comparable<T>>
    • remove

      public boolean remove(Object value)
      Removes from the list by making a new list with every element except the one given.

      Objects will be compared using the given objects equals() method.

      Specified by:
      remove in interface Collection<T extends Comparable<T>>
      Parameters:
      value - - value to remove.
    • removeAll

      public boolean removeAll(Collection<?> values)
      Specified by:
      removeAll in interface Collection<T extends Comparable<T>>
    • retainAll

      public boolean retainAll(Collection<?> values)
      Specified by:
      retainAll in interface Collection<T extends Comparable<T>>
    • remove

      public void remove(int index)
      Removes from the list by making a copy of every element except the one with the given index.
      Parameters:
      index - - index of the element to remove.
    • get

      public T get(int index)
      Retrieves an element by index.
      Parameters:
      index - - index of element to retrieve.
      Returns:
      The element at the given location.
    • size

      public int size()
      Retrieve the size of the list.
      Specified by:
      size in interface Collection<T extends Comparable<T>>
      Returns:
      Size of the list.
    • iterator

      public Iterator<T> iterator()
      Retrieves an iterator over the elements in the given list. Warning: No not attempt to remove elements using the iterator.
      Specified by:
      iterator in interface Collection<T extends Comparable<T>>
      Specified by:
      iterator in interface Iterable<T extends Comparable<T>>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T extends Comparable<T>>
    • contains

      public boolean contains(Object value)
      Specified by:
      contains in interface Collection<T extends Comparable<T>>
    • containsAll

      public boolean containsAll(Collection<?> values)
      Specified by:
      containsAll in interface Collection<T extends Comparable<T>>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T extends Comparable<T>>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T extends Comparable<T>>
    • toArray

      public <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<T extends Comparable<T>>
    • toString

      public String toString()
      Overrides:
      toString in class Object