Class IntegerSet

java.lang.Object
com.comphenix.protocol.concurrency.IntegerSet

public class IntegerSet extends Object
Represents a very quick integer set that uses a lookup table to store membership.

This class is intentionally missing a size method.

Author:
Kristian
  • Constructor Summary

    Constructors
    Constructor
    Description
    IntegerSet​(int maximumCount)
    Initialize a lookup table with the given maximum number of elements.
    IntegerSet​(int maximumCount, Collection<Integer> values)
    Initialize a lookup table with a given maximum and value list.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add​(int element)
    Add the given element to the set, or do nothing if it already exists.
    void
    addAll​(Collection<Integer> packets)
    Add the given collection of elements to the set.
    void
    Remove every element from the set.
    boolean
    contains​(int element)
    Determine whether or not the given element exists in the set.
    void
    remove​(int element)
    Remove the given element from the set, or do nothing if it's already removed.
    Convert the current IntegerSet to an equivalent HashSet.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IntegerSet

      public IntegerSet(int maximumCount)
      Initialize a lookup table with the given maximum number of elements.

      This creates a set for elements in the range [0, count).

      Formally, the current set must be a subset of [0, 1, 2, ..., count - 1].

      Parameters:
      maximumCount - - maximum element value and count.
    • IntegerSet

      public IntegerSet(int maximumCount, Collection<Integer> values)
      Initialize a lookup table with a given maximum and value list.

      The provided elements must be in the range [0, count).

      Parameters:
      maximumCount - - the maximum element value and count.
      values - - the elements to add to the set.
  • Method Details

    • contains

      public boolean contains(int element)
      Determine whether or not the given element exists in the set.
      Parameters:
      element - - the element to check. Must be in the range [0, count).
      Returns:
      TRUE if the given element exists, FALSE otherwise.
    • add

      public void add(int element)
      Add the given element to the set, or do nothing if it already exists.
      Parameters:
      element - - element to add.
      Throws:
      ArrayIndexOutOfBoundsException - If the given element is not in the range [0, count).
    • addAll

      public void addAll(Collection<Integer> packets)
      Add the given collection of elements to the set.
      Parameters:
      packets - - elements to add.
    • remove

      public void remove(int element)
      Remove the given element from the set, or do nothing if it's already removed.
      Parameters:
      element - - element to remove.
    • clear

      public void clear()
      Remove every element from the set.
    • toSet

      public Set<Integer> toSet()
      Convert the current IntegerSet to an equivalent HashSet.
      Returns:
      The resulting HashSet.