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 IntInterval
INFINITY
The interval[-Inf, +Inf]
.static IntInterval
MINUS_ONE
The interval[-1, -1]
.static IntInterval
ONE
The interval[1, 1]
.static IntInterval
ZERO
The 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 int
compareTo(IntInterval o)
IntInterval
diff(IntInterval other)
Performs the interval subtraction betweenthis
andother
.IntInterval
div(IntInterval other, boolean ignoreZero, boolean errorOnZero)
Performs the interval division betweenthis
andother
.boolean
equals(java.lang.Object obj)
MathNumber
getHigh()
Yields the upper bound of this interval.MathNumber
getLow()
Yields the lower bound of this interval.int
hashCode()
boolean
highIsPlusInfinity()
Yieldstrue
if the upper bound of this interval is set to plus infinity.boolean
includes(IntInterval other)
Yieldstrue
if this interval includes the given one.boolean
intersects(IntInterval other)
Yieldstrue
if this interval intersects with the given one.boolean
is(int n)
Yieldstrue
if this is a singleton interval containing onlyn
.boolean
isFinite()
Yieldstrue
if this is interval is finite, that is, if neither bound is set to infinity.boolean
isInfinite()
Yieldstrue
if this is interval is not finite, that is, if at least one bound is set to infinity.boolean
isInfinity()
Yieldstrue
if this is the interval representing infinity, that is,[-Inf, +Inf]
.boolean
isSingleton()
Yieldstrue
if 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()
boolean
lowIsMinusInfinity()
Yieldstrue
if the lower bound of this interval is set to minus infinity.IntInterval
mul(IntInterval other)
Performs the interval multiplication betweenthis
andother
.IntInterval
plus(IntInterval other)
Performs the interval addition betweenthis
andother
.java.lang.String
toString()
-
-
-
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., iflow
is 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., iflow
is 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., iflow
is 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()
Yieldstrue
if the lower bound of this interval is set to minus infinity.- Returns:
true
if that condition holds
-
highIsPlusInfinity
public boolean highIsPlusInfinity()
Yieldstrue
if the upper bound of this interval is set to plus infinity.- Returns:
true
if that condition holds
-
isInfinite
public boolean isInfinite()
Yieldstrue
if this is interval is not finite, that is, if at least one bound is set to infinity.- Returns:
true
if that condition holds
-
isFinite
public boolean isFinite()
Yieldstrue
if this is interval is finite, that is, if neither bound is set to infinity.- Returns:
true
if that condition holds
-
isInfinity
public boolean isInfinity()
Yieldstrue
if this is the interval representing infinity, that is,[-Inf, +Inf]
.- Returns:
true
if that condition holds
-
isSingleton
public boolean isSingleton()
Yieldstrue
if this is a singleton interval, that is, if the lower bound and the upper bound are the same.- Returns:
true
if that condition holds
-
is
public boolean is(int n)
Yieldstrue
if this is a singleton interval containing onlyn
.- Parameters:
n
- the integer to test- Returns:
true
if that condition holds
-
plus
public IntInterval plus(IntInterval other)
Performs the interval addition betweenthis
andother
.- Parameters:
other
- the other interval- Returns:
this + other
-
diff
public IntInterval diff(IntInterval other)
Performs the interval subtraction betweenthis
andother
.- Parameters:
other
- the other interval- Returns:
this - other
-
mul
public IntInterval mul(IntInterval other)
Performs the interval multiplication betweenthis
andother
.- Parameters:
other
- the other interval- Returns:
this * other
-
div
public IntInterval div(IntInterval other, boolean ignoreZero, boolean errorOnZero)
Performs the interval division betweenthis
andother
.- Parameters:
other
- the other intervalignoreZero
- iftrue
, causes the division to ignore the fact thatother
might contain 0, producing a smaller resulterrorOnZero
- whether or not anArithmeticException
should be thrown immediately ifother
contains zero- Returns:
this / other
- Throws:
java.lang.ArithmeticException
- ifother
contains 0 anderrorOnZero
is set totrue
-
includes
public boolean includes(IntInterval other)
Yieldstrue
if this interval includes the given one.- Parameters:
other
- the other interval- Returns:
true
if it is included,false
otherwise
-
intersects
public boolean intersects(IntInterval other)
Yieldstrue
if this interval intersects with the given one.- Parameters:
other
- the other interval- Returns:
true
if those intersects,false
otherwise
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
iterator
public java.util.Iterator<java.lang.Long> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Long>
-
compareTo
public int compareTo(IntInterval o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<IntInterval>
-
-