Package it.unive.lisa.util.numeric
Class IntInterval
- java.lang.Object
-
- it.unive.lisa.util.numeric.IntInterval
-
- All Implemented Interfaces:
java.lang.Comparable<IntInterval>,java.lang.Iterable<java.lang.Long>
public class IntInterval extends java.lang.Object implements java.lang.Iterable<java.lang.Long>, java.lang.Comparable<IntInterval>
An interval with integer bounds.
-
-
Field Summary
Fields Modifier and Type Field Description static IntIntervalINFINITYThe interval[-Inf, +Inf].static IntIntervalMINUS_ONEThe interval[-1, -1].static IntIntervalONEThe interval[1, 1].static IntIntervalZEROThe interval[0, 0].
-
Constructor Summary
Constructors Constructor Description IntInterval(int low, int high)Builds a new interval.IntInterval(MathNumber low, MathNumber high)Builds a new interval.IntInterval(java.lang.Integer low, java.lang.Integer high)Builds a new interval.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(IntInterval o)IntIntervaldiff(IntInterval other)Performs the interval subtraction betweenthisandother.IntIntervaldiv(IntInterval other, boolean ignoreZero, boolean errorOnZero)Performs the interval division betweenthisandother.booleanequals(java.lang.Object obj)MathNumbergetHigh()Yields the upper bound of this interval.MathNumbergetLow()Yields the lower bound of this interval.inthashCode()booleanhighIsPlusInfinity()Yieldstrueif the upper bound of this interval is set to plus infinity.booleanincludes(IntInterval other)Yieldstrueif this interval includes the given one.booleanintersects(IntInterval other)Yieldstrueif this interval intersects with the given one.booleanis(int n)Yieldstrueif this is a singleton interval containing onlyn.booleanisFinite()Yieldstrueif this is interval is finite, that is, if neither bound is set to infinity.booleanisInfinite()Yieldstrueif this is interval is not finite, that is, if at least one bound is set to infinity.booleanisInfinity()Yieldstrueif this is the interval representing infinity, that is,[-Inf, +Inf].booleanisSingleton()Yieldstrueif this is a singleton interval, that is, if the lower bound and the upper bound are the same.java.util.Iterator<java.lang.Long>iterator()booleanlowIsMinusInfinity()Yieldstrueif the lower bound of this interval is set to minus infinity.IntIntervalmul(IntInterval other)Performs the interval multiplication betweenthisandother.IntIntervalplus(IntInterval other)Performs the interval addition betweenthisandother.java.lang.StringtoString()
-
-
-
Field Detail
-
INFINITY
public static final IntInterval INFINITY
The interval[-Inf, +Inf].
-
ZERO
public static final IntInterval ZERO
The interval[0, 0].
-
ONE
public static final IntInterval ONE
The interval[1, 1].
-
MINUS_ONE
public static final IntInterval MINUS_ONE
The interval[-1, -1].
-
-
Constructor Detail
-
IntInterval
public IntInterval(int low, int high)Builds a new interval. Order of the bounds is adjusted (i.e., iflowis greater thenhigh, then the interval[high, low]is created).- Parameters:
low- the lower boundhigh- the upper bound
-
IntInterval
public IntInterval(java.lang.Integer low, java.lang.Integer high)Builds a new interval. Order of the bounds is adjusted (i.e., iflowis greater thenhigh, then the interval[high, low]is created).- Parameters:
low- the lower bound (ifnull, -inf will be used)high- the upper bound (ifnull, +inf will be used)
-
IntInterval
public IntInterval(MathNumber low, MathNumber high)
Builds a new interval. Order of the bounds is adjusted (i.e., iflowis greater thenhigh, then the interval[high, low]is created).- Parameters:
low- the lower boundhigh- the upper bound
-
-
Method Detail
-
getHigh
public MathNumber getHigh()
Yields the upper bound of this interval.- Returns:
- the upper bound of this interval
-
getLow
public MathNumber getLow()
Yields the lower bound of this interval.- Returns:
- the lower bound of this interval
-
lowIsMinusInfinity
public boolean lowIsMinusInfinity()
Yieldstrueif the lower bound of this interval is set to minus infinity.- Returns:
trueif that condition holds
-
highIsPlusInfinity
public boolean highIsPlusInfinity()
Yieldstrueif the upper bound of this interval is set to plus infinity.- Returns:
trueif that condition holds
-
isInfinite
public boolean isInfinite()
Yieldstrueif this is interval is not finite, that is, if at least one bound is set to infinity.- Returns:
trueif that condition holds
-
isFinite
public boolean isFinite()
Yieldstrueif this is interval is finite, that is, if neither bound is set to infinity.- Returns:
trueif that condition holds
-
isInfinity
public boolean isInfinity()
Yieldstrueif this is the interval representing infinity, that is,[-Inf, +Inf].- Returns:
trueif that condition holds
-
isSingleton
public boolean isSingleton()
Yieldstrueif this is a singleton interval, that is, if the lower bound and the upper bound are the same.- Returns:
trueif that condition holds
-
is
public boolean is(int n)
Yieldstrueif this is a singleton interval containing onlyn.- Parameters:
n- the integer to test- Returns:
trueif that condition holds
-
plus
public IntInterval plus(IntInterval other)
Performs the interval addition betweenthisandother.- Parameters:
other- the other interval- Returns:
this + other
-
diff
public IntInterval diff(IntInterval other)
Performs the interval subtraction betweenthisandother.- Parameters:
other- the other interval- Returns:
this - other
-
mul
public IntInterval mul(IntInterval other)
Performs the interval multiplication betweenthisandother.- Parameters:
other- the other interval- Returns:
this * other
-
div
public IntInterval div(IntInterval other, boolean ignoreZero, boolean errorOnZero)
Performs the interval division betweenthisandother.- Parameters:
other- the other intervalignoreZero- iftrue, causes the division to ignore the fact thatothermight contain 0, producing a smaller resulterrorOnZero- whether or not anArithmeticExceptionshould be thrown immediately ifothercontains zero- Returns:
this / other- Throws:
java.lang.ArithmeticException- ifothercontains 0 anderrorOnZerois set totrue
-
includes
public boolean includes(IntInterval other)
Yieldstrueif this interval includes the given one.- Parameters:
other- the other interval- Returns:
trueif it is included,falseotherwise
-
intersects
public boolean intersects(IntInterval other)
Yieldstrueif this interval intersects with the given one.- Parameters:
other- the other interval- Returns:
trueif those intersects,falseotherwise
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
iterator
public java.util.Iterator<java.lang.Long> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Long>
-
compareTo
public int compareTo(IntInterval o)
- Specified by:
compareToin interfacejava.lang.Comparable<IntInterval>
-
-