Package org.xcsp.common
Class Range
- java.lang.Object
-
- org.xcsp.common.Range
-
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 classRange.Rangesx2A class denoting a double range.static classRange.Rangesx3A class denoting a triple range.static classRange.Rangesx4A class denoting a quadruple range.static classRange.Rangesx5A class denoting a quintuple range.static classRange.Rangesx6A class denoting a sixtuple range.
-
Constructor Summary
Constructors Constructor Description Range(int length)Constructs an objectRangefrom the specified length (using implicitly a lower bound equal to 0 and a step equal to 1).Range(int startInclusive, int endExclusive)Constructs an objectRangefrom the specified bounds (using implicitly a step equal to 1).Range(int startInclusive, int endExclusive, int step)Constructs an objectRangefrom the specified bounds and step.Range(Values.IntegerInterval ii)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Rangeabs()Rangeadd(Range r)booleancontains(int i)Returnstrueiff this range contains the specified valuevoidexecute(java.util.function.IntConsumer c)Executes the specified consumer on each integer value contained in this range.booleanisBasic()Returnstrueiff this range is basic, i.e., starts at 0 and admits a step equal to 1Iterator<Integer>iterator()Returns an iterator over all integers in this range.intlength()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.Rangeneg()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.Rangesx2range(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.Rangesx2range(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.Rangesx2range(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.Rangesx2rangeClosed(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.Rangesx2rangeClosed(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.IntStreamstream()Converts this range into a stream.int[]toArray()Returns a 1-dimensional array containing all integers in this range.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
Range
public Range(int startInclusive, int endExclusive, int step)Constructs an objectRangefrom the specified bounds and step.- Parameters:
startInclusive- the lower bound (inclusive) of this rangeendExclusive- the upper bound (exclusive) of this rangestep- the step of this range
-
Range
public Range(int startInclusive, int endExclusive)Constructs an objectRangefrom the specified bounds (using implicitly a step equal to 1).- Parameters:
startInclusive- the lower bound (inclusive) of this rangerange.startInclusiveendExclusive- the upper bound (exclusive) of this range
-
Range
public Range(int length)
Constructs an objectRangefrom the specified length (using implicitly a lower bound equal to 0 and a step equal to 1).- Parameters:
length- the length of this range
-
Range
public Range(Values.IntegerInterval ii)
-
-
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 builtendExclusive- the upper bound (exclusive) of the second range to be builtstep- 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 builtendInclusive- the upper bound (inclusive) of the second range to be builtstep- 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 builtendExclusive- 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 builtendInclusive- 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()
Returnstrueiff this range is basic, i.e., starts at 0 and admits a step equal to 1- Returns:
trueiff this range is basic,
-
contains
public boolean contains(int i)
Returnstrueiff this range contains the specified value- Parameters:
i- an integer- Returns:
trueiff 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 thatnullvalues are simply discarded, if ever generated. Be careful: in case, no variable is obtained,nullis 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 anintinto anotherint- 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
-
-