Interface IntSet

All Known Implementing Classes:
IntervalSet

public interface IntSet
A generic set of integers.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int el)
    Adds the specified value to the current set.
    Modify the current IntSet object to contain all elements that are present in itself, the specified set, or both.
    Return a new IntSet object containing all elements that are present in both the current set and the specified set a.
    complement(IntSet elements)
    Return a new IntSet object containing all elements that are present in elements but not present in the current set.
    boolean
    contains(int el)
    Returns true if the set contains the specified element.
    boolean
    boolean
    Returns true if this set contains no elements.
    Return a new IntSet object containing all elements that are present in the current set, the specified set a, or both.
    void
    remove(int el)
    Removes the specified value from the current set.
    int
    Return the total number of elements represented by the current set.
    Return a new IntSet object containing all elements that are present in the current set but not present in the input set a.
    Return a list containing the elements represented by the current set.
  • Method Details

    • add

      void add(int el)
      Adds the specified value to the current set.
      Parameters:
      el - the value to add
      Throws:
      IllegalStateException - if the current set is read-only
    • addAll

      IntSet addAll(IntSet set)
      Modify the current IntSet object to contain all elements that are present in itself, the specified set, or both.
      Parameters:
      set - The set to add to the current set. A null argument is treated as though it were an empty set.
      Returns:
      this (to support chained calls)
      Throws:
      IllegalStateException - if the current set is read-only
    • and

      IntSet and(IntSet a)
      Return a new IntSet object containing all elements that are present in both the current set and the specified set a.
      Parameters:
      a - The set to intersect with the current set. A null argument is treated as though it were an empty set.
      Returns:
      A new IntSet instance containing the intersection of the current set and a. The value null may be returned in place of an empty result set.
    • complement

      IntSet complement(IntSet elements)
      Return a new IntSet object containing all elements that are present in elements but not present in the current set. The following expressions are equivalent for input non-null IntSet instances x and y.
      • x.complement(y)
      • y.subtract(x)
      Parameters:
      elements - The set to compare with the current set. A null argument is treated as though it were an empty set.
      Returns:
      A new IntSet instance containing the elements present in elements but not present in the current set. The value null may be returned in place of an empty result set.
    • or

      IntSet or(IntSet a)
      Return a new IntSet object containing all elements that are present in the current set, the specified set a, or both.

      This method is similar to addAll(IntSet), but returns a new IntSet instance instead of modifying the current set.

      Parameters:
      a - The set to union with the current set. A null argument is treated as though it were an empty set.
      Returns:
      A new IntSet instance containing the union of the current set and a. The value null may be returned in place of an empty result set.
    • subtract

      IntSet subtract(IntSet a)
      Return a new IntSet object containing all elements that are present in the current set but not present in the input set a. The following expressions are equivalent for input non-null IntSet instances x and y.
      • y.subtract(x)
      • x.complement(y)
      Parameters:
      a - The set to compare with the current set. A null argument is treated as though it were an empty set.
      Returns:
      A new IntSet instance containing the elements present in elements but not present in the current set. The value null may be returned in place of an empty result set.
    • size

      int size()
      Return the total number of elements represented by the current set.
      Returns:
      the total number of elements represented by the current set, regardless of the manner in which the elements are stored.
    • isNil

      boolean isNil()
      Returns true if this set contains no elements.
      Returns:
      true if the current set contains no elements; otherwise, false.
    • equals

      boolean equals(Object obj)
      Overrides:
      equals in class Object
    • contains

      boolean contains(int el)
      Returns true if the set contains the specified element.
      Parameters:
      el - The element to check for.
      Returns:
      true if the set contains el; otherwise false.
    • remove

      void remove(int el)
      Removes the specified value from the current set. If the current set does not contain the element, no changes are made.
      Parameters:
      el - the value to remove
      Throws:
      IllegalStateException - if the current set is read-only
    • toList

      List<Integer> toList()
      Return a list containing the elements represented by the current set. The list is returned in ascending numerical order.
      Returns:
      A list containing all element present in the current set, sorted in ascending numerical order.
    • toString

      String toString()
      Overrides:
      toString in class Object