Class IntegerSet

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Integer>, Collection<Integer>, Iterator, NavigableSet<Integer>, SequencedCollection<Integer>, SequencedSet<Integer>, Set<Integer>, SortedSet<Integer>

public class IntegerSet extends TreeSet<Integer> implements Iterator
This class extends TreeSet and implements a navigable set of Integer elements.
See Also:
  • Constructor Details

    • IntegerSet

      public IntegerSet(Comparator<Long> c)
    • IntegerSet

      public IntegerSet(Integer... ii)
      Creates a new IntegerSet and fills it with the Integer values passed as parameters. The IntegerSet is sorted according to the natural ordering of its elements.
      Parameters:
      ii - A variable number of Integer values that will fill the IntegerSet
    • IntegerSet

      public IntegerSet(Collection<Integer> c)
      Creates a new IntegerSet and fills it with all the elements of the Collection passed as parameter; the elements in the collection must be of type Integer. The IntegerSet is sorted according to the natural ordering of its elements.
      Parameters:
      c - The Collection of Integer values that will fill the IntegerSet
    • IntegerSet

      public IntegerSet()
      Creates a new empty IntegerSet, sorted according to the natural ordering of its elements.
    • IntegerSet

      public IntegerSet(String s)
      Creates a new IntegerSet starting from the values contained in the string. Each value must be separated from the next by the comma (,). It is possible to indicate ranges of values by separating the start and end of the range using the minus character (-); the values between the beginning and the end of the range will all be included in the IntegerSet.
      The IntegerSet is sorted according to the natural ordering of its elements.
      Parameters:
      s - The string that contains the values that will fill the IntegerSet
    • IntegerSet

      public IntegerSet(String s, char delim, char rangedelim)
      Creates a new IntegerSet starting from the values contained in the string. Each value must be separated from the next by the delimiter character passed as second parameter. It is possible to indicate ranges of values by separating the start and end of the range using the range delimiter character passed as last parameter; the values between the beginning and the end of the range will all be included in the IntegerSet.
      The IntegerSet is sorted according to the natural ordering of its elements.
      Parameters:
      s - The string that contains the values that will fill the IntegerSet
      delim - The character that defines the values separator
      rangedelim - The character that defines the range separator
  • Method Details

    • toString

      public String toString()
      Returns the string version of the IntegerSet, i.e. a string in which every value is separated from the next by the comma (,) character.
      Overrides:
      toString in class AbstractCollection<Integer>
      Returns:
      The string that represents the IntegerSet
    • toString

      public String toString(char delim)
      Returns the string version of the IntegerSet, i.e. a string in which every value is separated from the next by the delimiter character passed as parameter
      Parameters:
      delim - The character used to separate each value
      Returns:
      The string that represents the IntegerSet
    • scanNext

      protected void scanNext()
    • intervalsIterator

      public Iterator intervalsIterator()
      Returns an Iterator over the intervals (ranges) defined for the IntegerSet
      Returns:
      The Iterator in which every element is a values interval
    • hasNext

      public boolean hasNext()
      Checks if the intervals Iterator (see intervalsIterator()) has a next elements
      Specified by:
      hasNext in interface Iterator
      Returns:
      true if the Iterator has at least another element, false otherwise
    • next

      public IntegerSet next()
      Returns the next element of the intervals Iterator (see intervalsIterator())
      Specified by:
      next in interface Iterator
      Returns:
      The IntegerSet that is the next element in the iteration
    • remove

      public void remove()
      Empty method
      Specified by:
      remove in interface Iterator
    • toIntervalsString

      public String toIntervalsString()
      Returns a string version of the IntegerSet in which the values are expressed in range form. Each range is indicated by the initial and the final value, separated by the minus sign (-), and each range is separated by the next one with the comma (,).
      Returns:
      The string that represents the range version of the IntegerSet values
    • toIntervalsString

      public String toIntervalsString(char delim, char rangedelim)
      Returns a string version of the IntegerSet in which the values are expressed in range form. Each range is indicated by the initial and the final value, separated by the range delimiter character passed as second parameter. Each range is separated by the next one with the delimiter character, passed es first parameter.
      Parameters:
      delim - The character used to separate each range
      rangedelim - The character that defines the range separator
      Returns:
      The string that represents the range version of the IntegerSet values