Class IntSet

java.lang.Object
org.apache.uima.internal.util.IntSet
All Implemented Interfaces:
PositiveIntSet

public class IntSet extends Object implements PositiveIntSet
This class implements a set of integers. It does not implement the Set interface for performance reasons, though methods with the same name are equivalent. This does not implement shorts + offset, like the IntHashSet does because by the time that might be of interest, we would switch to IntHashSet to get ~O(1) operations including contains.
  • Field Details

  • Constructor Details

    • IntSet

      public IntSet()
      Creates a new instance of this set.
    • IntSet

      public IntSet(int capacity)
      Parameters:
      capacity - allocate enough space to hold at least this before expanding
  • Method Details

    • add

      public boolean add(int element)
      Adds the specified int to this set.
      Specified by:
      add in interface PositiveIntSet
      Parameters:
      element - the integer to be added.
      Returns:
      true if this set did not already contain this element, false otherwise.
    • contains

      public boolean contains(int element)
      Tests if this set contains the specified element.
      Specified by:
      contains in interface PositiveIntSet
      Parameters:
      element - the element to be tested.
      Returns:
      true if the element is contained in this set, false otherwise.
    • find

      public int find(int element)
      Specified by:
      find in interface PositiveIntSet
      Parameters:
      element - an item which may be in the set
      Returns:
      -1 if the item is not in the set, or a position value that can be used with iterators to start at that item.
    • size

      public int size()
      Specified by:
      size in interface PositiveIntSet
      Returns:
      the size of this set.
    • get

      public int get(int n)
      Used for FsBagIndex, and internally to compute most positive/neg
      Specified by:
      get in interface PositiveIntSet
      Parameters:
      n - the position
      Returns:
      the value at that position
    • removeElementAt

      public void removeElementAt(int n)
      Removes the n-th element in this set.
      Parameters:
      n - -
    • equals

      public boolean equals(Object o)
      Tests if two sets are equal. This is the case if the two sets are of the same size, and every element in one set in contained in the other set.
      Note that in order to increase performance, before the sets are actually compared the way described above, the sums of the elements in both sets are calculated, ignoring possible int overflows. If the sums are not equal, the two sets cannot be equal. In case the sums are equal, the two sets are compared element by element.
      Overrides:
      equals in class Object
      Parameters:
      o - the set to be tested for equality with this set.
      Returns:
      true if the sets are equal, false otherwise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • indexOf

      public int indexOf(int element)
    • clear

      public void clear()
      Description copied from interface: PositiveIntSet
      remove all members of the set
      Specified by:
      clear in interface PositiveIntSet
    • remove

      public boolean remove(int key)
      Specified by:
      remove in interface PositiveIntSet
      Parameters:
      key - -
      Returns:
      true if the set had this element before the remove
    • iterator

      public IntSet.IntSetIterator iterator()
      Specified by:
      iterator in interface PositiveIntSet
      Returns:
      an iterator (may be ordered or unordered) over the members of the set
    • moveToFirst

      public int moveToFirst()
      Description copied from interface: PositiveIntSet
      For FSBagIndex low level iterator use
      Specified by:
      moveToFirst in interface PositiveIntSet
      Returns:
      the position of the first element, or -1;
    • moveToLast

      public int moveToLast()
      Description copied from interface: PositiveIntSet
      For FSBagIndex low level iterator use
      Specified by:
      moveToLast in interface PositiveIntSet
      Returns:
      the position of the last element, or -1;
    • moveToNext

      public int moveToNext(int position)
      Description copied from interface: PositiveIntSet
      For FSBagIndex low level iterator use
      Specified by:
      moveToNext in interface PositiveIntSet
      Parameters:
      position - -
      Returns:
      the position of the next element, or -1;
    • moveToPrevious

      public int moveToPrevious(int position)
      Description copied from interface: PositiveIntSet
      For FSBagIndex low level iterator use
      Specified by:
      moveToPrevious in interface PositiveIntSet
      Parameters:
      position - -
      Returns:
      the position of the next element, or -1;
    • isValid

      public boolean isValid(int position)
      Description copied from interface: PositiveIntSet
      For FSBagIndex low level iterator use
      Specified by:
      isValid in interface PositiveIntSet
      Parameters:
      position - -
      Returns:
      true if the position is between the first and last element inclusive.
    • bulkAddTo

      public void bulkAddTo(IntVector v)
      Description copied from interface: PositiveIntSet
      add all elements in this set to the IntVector v as a bulk operation
      Specified by:
      bulkAddTo in interface PositiveIntSet
      Parameters:
      v - - to be added to
    • toIntArray

      public int[] toIntArray()
      Specified by:
      toIntArray in interface PositiveIntSet
      Returns:
      the set as an arbitrarily ordered int array
    • toString

      public String toString()
      Overrides:
      toString in class Object