Class RangeSet

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Integer>, Collection<Integer>, Set<Integer>

public class RangeSet extends AbstractSet<Integer> implements Cloneable, Serializable
Exposes a range of integer values as a set. Avoids the allocation of storage for all values. Order of elements is guaranteed to be in the order from the specified start and stop values.

If combination of start/stop/step values are not mathematically possible to represent as a set of values, it is represented by this implementation as an empty set.

See Also:
  • Constructor Details

    • RangeSet

      public RangeSet(int stop)
      Constructs a range set for a sequence of numbers, starting at 0 with the value to stop. Equivalent to constructing the range set with: RangeSet(0, stop, 1).
      Parameters:
      stop - the point at which to stop the range (exclusive).
    • RangeSet

      public RangeSet(int start, int stop)
      Constructs a range set for the specified range of integers with a step of 1. Equivalent to constructing the range set with: RangeSet(start, stop, 1).
      Parameters:
      start - the start of the range (inclusive).
      stop - the point at which to stop the range (exclusive).
    • RangeSet

      public RangeSet(int start, int stop, int step)
      Constructs a range set for the specified range of integers and increment.
      Parameters:
      start - the start of the range, inclusive.
      stop - the point at which to stop the range (exclusive).
      step - the step to increment for each value in the range.
      Throws:
      IllegalArgumentException - if step is 0.
  • Method Details