Class Range

  • All Implemented Interfaces:
    Iterable<Integer>

    public class Range
    extends Object
    implements Iterable<Integer>
    This class includes all functionalities that are necessary to deal with ranges of integers. Inner classes represent double, triple, quadruple and quintuple forms of ranges, used to represent Cartesian products.
    Author:
    Christophe Lecoutre
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Range.Rangesx2
      A class denoting a double range.
      static class  Range.Rangesx3
      A class denoting a triple range.
      static class  Range.Rangesx4
      A class denoting a quadruple range.
      static class  Range.Rangesx5
      A class denoting a quintuple range.
      static class  Range.Rangesx6
      A class denoting a sixtuple range.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int start
      The lower bound (inclusive) of this range.
      int step
      The step of this range (difference between each two successive numbers in this range).
      int stop
      The upper bound (exclusive) of this range.
    • Constructor Summary

      Constructors 
      Constructor Description
      Range​(int length)
      Constructs an object Range from the specified length (using implicitly a lower bound equal to 0 and a step equal to 1).
      Range​(int startInclusive, int endExclusive)
      Constructs an object Range from the specified bounds (using implicitly a step equal to 1).
      Range​(int startInclusive, int endExclusive, int step)
      Constructs an object Range from the specified bounds and step.
      Range​(Values.IntegerInterval ii)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Range abs()  
      Range add​(Range r)  
      boolean contains​(int i)
      Returns true iff this range contains the specified value
      void execute​(java.util.function.IntConsumer c)
      Executes the specified consumer on each integer value contained in this range.
      boolean isBasic()
      Returns true iff this range is basic, i.e., starts at 0 and admits a step equal to 1
      Iterator<Integer> iterator()
      Returns an iterator over all integers in this range.
      int length()
      Returns the length (number of integers) in this range.
      int[] map​(java.util.function.IntUnaryOperator op)
      Returns a 1-dimensional array of integers, obtained after mapping every integer in this range in a value given by the specified unary operator.
      <T> T[] mapToObj​(java.util.function.IntFunction<T> f)
      Returns a 1-dimensional array of objects (from class T), obtained after collecting the objects returned by the specified function when executed on all values in this range.
      Range neg()  
      int[][] provideTuples​(java.util.function.IntFunction<int[]> f)
      Deprecated.
      int[] provideVals​(java.util.function.IntFunction<Integer> f)
      Deprecated.
      <T extends IVar>
      T[]
      provideVars​(java.util.function.IntFunction<T> f)
      Deprecated.
      Range.Rangesx2 range​(int length)
      Returns a double range obtained by combining this range with a range built from the specified length (using implicitly a lower bound equal to 0 and a step equal to 1).
      Range.Rangesx2 range​(int startInclusive, int endExclusive)
      Returns a double range obtained by combining this range with a range built from the specified bounds (using implicitly a step equal to 1).
      Range.Rangesx2 range​(int startInclusive, int endExclusive, int step)
      Returns a double range obtained by combining this range with a range built from the specified bounds and step.
      Range.Rangesx2 rangeClosed​(int startInclusive, int endInclusive)
      Returns a double range obtained by combining this range with a range built from the specified bounds (using implicitly a step equal to 1).
      Range.Rangesx2 rangeClosed​(int startInclusive, int endInclusive, int step)
      Returns a double range obtained by combining this range with a range built from the specified bounds and step.
      int[] select​(FunctionalInterfaces.Intx1Predicate p)
      Builds and returns a 1-dimensional array of integers, obtained by selecting from this range any integer that satisfies the specified predicate.
      java.util.stream.IntStream stream()
      Converts this range into a stream.
      int[] toArray()
      Returns a 1-dimensional array containing all integers in this range.
      String toString()  
    • Field Detail

      • start

        public final int start
        The lower bound (inclusive) of this range.
      • stop

        public final int stop
        The upper bound (exclusive) of this range.
      • step

        public final int step
        The step of this range (difference between each two successive numbers in this range).
    • Constructor Detail

      • Range

        public Range​(int startInclusive,
                     int endExclusive,
                     int step)
        Constructs an object Range from the specified bounds and step.
        Parameters:
        startInclusive - the lower bound (inclusive) of this range
        endExclusive - the upper bound (exclusive) of this range
        step - the step of this range
      • Range

        public Range​(int startInclusive,
                     int endExclusive)
        Constructs an object Range from the specified bounds (using implicitly a step equal to 1).
        Parameters:
        startInclusive - the lower bound (inclusive) of this rangerange.startInclusive
        endExclusive - the upper bound (exclusive) of this range
      • Range

        public Range​(int length)
        Constructs an object Range from the specified length (using implicitly a lower bound equal to 0 and a step equal to 1).
        Parameters:
        length - the length of this range
    • Method Detail

      • range

        public Range.Rangesx2 range​(int startInclusive,
                                    int endExclusive,
                                    int step)
        Returns a double range obtained by combining this range with a range built from the specified bounds and step.
        Parameters:
        startInclusive - the lower bound (inclusive) of the second range to be built
        endExclusive - the upper bound (exclusive) of the second range to be built
        step - the step of the second range to be built
        Returns:
        a double range obtained by combining this range with a range built from the specified bounds and step
      • rangeClosed

        public Range.Rangesx2 rangeClosed​(int startInclusive,
                                          int endInclusive,
                                          int step)
        Returns a double range obtained by combining this range with a range built from the specified bounds and step.
        Parameters:
        startInclusive - the lower bound (inclusive) of the second range to be built
        endInclusive - the upper bound (inclusive) of the second range to be built
        step - the step of the second range to be built
        Returns:
        a double range obtained by combining this range with a range built from the specified bounds and step
      • range

        public Range.Rangesx2 range​(int startInclusive,
                                    int endExclusive)
        Returns a double range obtained by combining this range with a range built from the specified bounds (using implicitly a step equal to 1).
        Parameters:
        startInclusive - the lower bound (inclusive) of the second range to be built
        endExclusive - the upper bound (exclusive) of the second range to be built
        Returns:
        a double range obtained by combining this range with a range built from the specified bounds
      • rangeClosed

        public Range.Rangesx2 rangeClosed​(int startInclusive,
                                          int endInclusive)
        Returns a double range obtained by combining this range with a range built from the specified bounds (using implicitly a step equal to 1).
        Parameters:
        startInclusive - the lower bound (inclusive) of the second range to be built
        endInclusive - the upper bound (inclusive) of the second range to be built
        Returns:
        a double range obtained by combining this range with a range built from the specified bounds
      • range

        public Range.Rangesx2 range​(int length)
        Returns a double range obtained by combining this range with a range built from the specified length (using implicitly a lower bound equal to 0 and a step equal to 1).
        Parameters:
        length - the length of the second range
        Returns:
        a double range by combining this range with a range built from the specified length
      • isBasic

        public boolean isBasic()
        Returns true iff this range is basic, i.e., starts at 0 and admits a step equal to 1
        Returns:
        true iff this range is basic,
      • contains

        public boolean contains​(int i)
        Returns true iff this range contains the specified value
        Parameters:
        i - an integer
        Returns:
        true iff this range contains the specified value
      • length

        public int length()
        Returns the length (number of integers) in this range.
        Returns:
        the length (number of integers) in this range
      • neg

        public Range neg()
      • abs

        public Range abs()
      • select

        public int[] select​(FunctionalInterfaces.Intx1Predicate p)
        Builds and returns a 1-dimensional array of integers, obtained by selecting from this range any integer that satisfies the specified predicate.
        Parameters:
        p - a predicate allowing us to test if a value in this range must be selected
        Returns:
        a 1-dimensional array of integers (possibly, of length 0)
      • mapToObj

        public <T> T[] mapToObj​(java.util.function.IntFunction<T> f)
        Returns a 1-dimensional array of objects (from class T), obtained after collecting the objects returned by the specified function when executed on all values in this range. Note that null values are simply discarded, if ever generated. Be careful: in case, no variable is obtained, null is returned.
        Parameters:
        f - a function to convert integer values into objects of class T
        Returns:
        a non-empty 1-dimensional array of objects or null
      • provideVars

        @Deprecated
        public <T extends IVar> T[] provideVars​(java.util.function.IntFunction<T> f)
        Deprecated.
      • provideVals

        @Deprecated
        public int[] provideVals​(java.util.function.IntFunction<Integer> f)
        Deprecated.
      • provideTuples

        @Deprecated
        public int[][] provideTuples​(java.util.function.IntFunction<int[]> f)
        Deprecated.
      • map

        public int[] map​(java.util.function.IntUnaryOperator op)
        Returns a 1-dimensional array of integers, obtained after mapping every integer in this range in a value given by the specified unary operator.
        Parameters:
        op - a unary operator that converts an int into another int
        Returns:
        a 1-dimensional array of integers
      • execute

        public void execute​(java.util.function.IntConsumer c)
        Executes the specified consumer on each integer value contained in this range.
        Parameters:
        c - an integer value consumer
      • toArray

        public int[] toArray()
        Returns a 1-dimensional array containing all integers in this range.
        Returns:
        a 1-dimensional array containing all integers in this range
      • stream

        public java.util.stream.IntStream stream()
        Converts this range into a stream.
        Returns:
        the stream corresponding to this range