java.lang.Cloneable
, java.lang.Iterable<java.lang.Integer>
public class Interval
extends java.lang.Object
implements java.lang.Iterable<java.lang.Integer>, java.lang.Cloneable
[glb, lub]
.MultiInterval
Modifier and Type | Field | Description |
---|---|---|
static int |
INF |
Minimum representable value.
|
static int |
SUP |
Maximum representable value.
|
Constructor | Description |
---|---|
Interval() |
Builds an empty interval.
|
Interval(java.lang.Integer x) |
Builds the interval
[x, x] , i.e. the singleton
{x} . |
Interval(java.lang.Integer lb,
java.lang.Integer ub) |
Builds the interval
[lb, ub] . |
Interval(java.util.Set<java.lang.Integer> set) |
Construct a new interval which contains every representable value in
set . |
Interval(Interval interval) |
Constructs a copy of the
Interval . |
Modifier and Type | Method | Description |
---|---|---|
Interval |
clone() |
Creates and returns a copy of
this . |
boolean |
contains(java.lang.Integer x) |
Checks if
x is an element of this . |
boolean |
equals(java.lang.Object obj) |
Returns
true if and only if this is equal
to obj . |
java.lang.Integer |
getGlb() |
Returns the greatest lower bound of
this . |
java.lang.Integer |
getLub() |
Returns the least upper bound of
this . |
Interval |
intersect(Interval interval) |
Returns the interval corresponding to the intersection between
this and interval . |
boolean |
isEmpty() |
Returns
true if and only if this is empty. |
boolean |
isSingleton() |
Returns
true if and only if this interval contains exactly one value. |
boolean |
isUniverse() |
Returns
true if and only if this interval contains every representable value. |
java.util.Iterator<java.lang.Integer> |
iterator() |
Returns an iterator for the interval.
|
Interval |
opposite() |
Returns the opposite of this interval.
|
int |
size() |
Returns the size of
this , i.e. the cardinality of the
set of integers corresponding to this . |
Interval |
sub(Interval interval) |
Returns the difference of
this and interval . |
boolean |
subset(Interval interval) |
Checks if
interval contains this . |
Interval |
sum(Interval interval) |
Returns the sum of
this and interval . |
java.util.TreeSet<java.lang.Integer> |
toSet() |
Returns a
TreeSet containing each element in the interval. |
java.lang.String |
toString() |
Returns a string representation of
this . |
static Interval |
universe() |
Returns an interval representing the entire universe of representable values.
|
public static final int SUP
public static final int INF
public Interval()
public Interval(@NotNull Interval interval)
Interval
.interval
- an interval.public Interval(@NotNull java.lang.Integer x)
[x, x]
, i.e. the singleton
{x}
.x
- the only element of the interval.public Interval(@NotNull java.lang.Integer lb, @NotNull java.lang.Integer ub)
[lb, ub]
.
Note that if lb greater than ub
, it constructs the empty
interval.
Note that if up
is lower than the minimum representable value, or if
lb
is greater than the maximum representable value, then the empty interval is constructed.lb
- the lower bound.ub
- the upper bound.public Interval(@NotNull java.util.Set<java.lang.Integer> set)
set
.
Such interval is equal to [glb set, lub set] if set
has only representable values,
otherwise non representable values are ignored.
If there are no representable values in set
the empty interval is constructed.set
- The set whose elements define the interval.@NotNull public static Interval universe()
public boolean contains(@NotNull java.lang.Integer x)
x
is an element of this
.x
- the element.true
if x
belongs to
this
, false
otherwise.public boolean subset(@NotNull Interval interval)
interval
contains this
.interval
- the interval.true
if interval
is a subset of
this
, false
otherwise.public boolean isEmpty()
true
if and only if this
is empty.true
if this
is empty,
false
otherwise.public boolean isSingleton()
true
if and only if this
interval contains exactly one value.true
if this
interval has size 1,
false
otherwise.public boolean isUniverse()
true
if and only if this
interval contains every representable value.true
if this
interval contains every representable value,
false
otherwise.public int size()
this
, i.e. the cardinality of the
set of integers corresponding to this
.@NotNull public java.lang.Integer getGlb()
this
.@NotNull public java.lang.Integer getLub()
this
.@NotNull public Interval intersect(@NotNull Interval interval)
this
and interval
.interval
- the second operand of the intersection.@NotNull public Interval sum(@NotNull Interval interval)
this
and interval
.
X = [a, b]
and
Y = [c, d]
the sum will be
X + Y = [a + c, b + d]
interval
- the second operand of the sum.this + interval
@NotNull public Interval sub(@NotNull Interval interval)
this
and interval
.
X = [a, b]
and
Y = [c, d]
the difference will be
X - Y = [a - d, b - c]
interval
- the second operand of the difference.this - interval
.@NotNull public Interval opposite()
@NotNull public java.util.TreeSet<java.lang.Integer> toSet()
TreeSet
containing each element in the interval.TreeSet
containing the elements of the interval.@NotNull public java.util.Iterator<java.lang.Integer> iterator()
iterator
in interface java.lang.Iterable<java.lang.Integer>
@NotNull public Interval clone()
this
.public boolean equals(@Nullable java.lang.Object obj)
true
if and only if this
is equal
to obj
.equals
in class java.lang.Object
true
if the intervals are equal, false
otherwise.@NotNull public java.lang.String toString()
this
.toString
in class java.lang.Object