java.lang.Cloneable
, java.lang.Iterable<java.lang.Integer>
, java.util.Collection<java.lang.Integer>
, java.util.Set<java.lang.Integer>
public class MultiInterval
extends java.lang.Object
implements java.util.Set<java.lang.Integer>, java.lang.Cloneable
[a_1, b_1] U [a_2, b_2] U ... U [a_n, b_n]
in which for
each i = 1, ..., n
we have that a_i <= b_i
and
for each j > i
we have that b_i < a_j - 1
.Interval
Modifier and Type | Field | Description |
---|---|---|
static int |
INF |
Infimum, Lowest representable value
|
static int |
SUP |
Supremum, greatest representable value.
|
Constructor | Description |
---|---|
MultiInterval() |
Builds an empty multi-interval.
|
MultiInterval(java.lang.Integer a) |
Builds a multi-interval of the form
[a, a] = {a} . |
MultiInterval(java.lang.Integer glb,
java.lang.Integer lub) |
Builds a multi-interval of the form
[glb, lub] . |
MultiInterval(java.util.Collection<Interval> col) |
Builds the multi-interval from a collection of intervals.
|
MultiInterval(java.util.Set<java.lang.Integer> set) |
Builds the multi-interval from a set of integers.
|
MultiInterval(Interval interval) |
Builds the multi-interval corresponding to the interval
interval . |
MultiInterval(MultiInterval multiInterval) |
Constructs a copy of the
MultiInterval . |
Modifier and Type | Method | Description |
---|---|---|
boolean |
add(java.lang.Integer value) |
Adds an integer value to this multi-interval.
|
boolean |
addAll(java.util.Collection<? extends java.lang.Integer> collection) |
Adds all the integer of
collection to the multi-interval. |
void |
clear() |
Empties this multi-interval.
|
MultiInterval |
clone() |
Creates and returns a copy of
this . |
MultiInterval |
complement() |
Returns the multi-interval corresponding to the complement of
this with respect to the universe multi-interval. |
MultiInterval |
complement(MultiInterval universe) |
Returns the result of the complement operation using the given multi-interval as universe.
|
boolean |
contains(java.lang.Integer value) |
Checks if
value belongs to one of the intervals of
this . |
boolean |
contains(java.lang.Object object) |
Checks whether this multi-interval contains
object or not. |
boolean |
containsAll(java.util.Collection<?> collection) |
Checks whether this multi-interval contains all the elements of
collection . |
Interval |
convexClosure() |
Returns the convex closure of
this , i.e. the minimum
convex set containing this . |
MultiInterval |
diff(MultiInterval multiInterval) |
Returns the multi-interval corresponding to the set difference between
this and multiInterval . |
boolean |
equals(java.lang.Object object) |
Checks whether
this is equal to object . |
java.lang.Integer |
getGlb() |
Returns the greatest lower bound of
this . |
java.lang.Integer |
getLub() |
Returns the least upper bound of
this . |
int |
getOrder() |
Returns the order of
this , i.e.,
the number of intervals that form this multi-interval. |
int |
hashCode() |
|
MultiInterval |
intersect(MultiInterval multiInterval) |
Returns the multi-interval corresponding to the intersection between
this and multiInterval . |
boolean |
isEmpty() |
Checks whether this multi-interval represents the empty set or not.
|
boolean |
isSingleton() |
Checks whether this multi-interval is a singleton or not.
|
boolean |
isUniverse() |
Checks if
this is the 'universe', i.e. the maximum
representable multi-interval. |
java.util.Iterator<java.lang.Integer> |
iterator() |
Returns an iterator over the elements of this multi-interval.
|
MultiInterval |
opposite() |
Returns a new multi-interval in wich each interval is the opposite of the original
|
boolean |
remove(java.lang.Object object) |
Removes an integer from this multi-interval.
|
boolean |
removeAll(java.util.Collection<?> collection) |
Removes all elements (which must be integers) of
collection from this . |
boolean |
retainAll(java.util.Collection<?> collection) |
Removes each integer that is not an element of
collection from this multi-interval. |
int |
size() |
Returns the size of the multi-interval, i.e. the number of its elements.
|
MultiInterval |
sub(MultiInterval multiInterval) |
Returns the difference of
this and multiInterval . |
boolean |
subset(MultiInterval multiInterval) |
Checks if
this is a subset of multiInterval . |
MultiInterval |
sum(MultiInterval multiInterval) |
Returns the sum of
this and multiInterval . |
java.lang.Object[] |
toArray() |
Returns an array containing all integers that are elements of
this . |
<T> T[] |
toArray(T[] array) |
Puts all integers in
this into array , if it can contain them, otherwise
creates a new array and puts all the integers into it. |
java.util.Set<java.lang.Integer> |
toSet() |
Returns a
Set representation of this . |
java.lang.String |
toString() |
Returns a string representation of
this . |
MultiInterval |
union(MultiInterval multiInterval) |
Returns the multi-interval corresponding to the union between
this and multiInterval . |
static MultiInterval |
universe() |
Returns the multi-interval corresponding to the 'universe', i.e. the
maximum representable multi-interval.
|
public static int INF
public static int SUP
public MultiInterval()
public MultiInterval(@NotNull MultiInterval multiInterval)
MultiInterval
.multiInterval
- the multi interval to copy.public MultiInterval(@NotNull java.lang.Integer a)
[a, a] = {a}
.a
- the only element of the set.public MultiInterval(@NotNull java.lang.Integer glb, @NotNull java.lang.Integer lub)
[glb, lub]
.glb
- the lower bound of the interval.lub
- the upper bound of the interval.public MultiInterval(@NotNull Interval interval)
interval
.interval
- the only interval of the set.public MultiInterval(@NotNull java.util.Set<java.lang.Integer> set)
set
- the set of integers. It must not contain null
values.java.lang.NullPointerException
- if set
contains null
values.@NotNull public static MultiInterval universe()
public boolean contains(@NotNull java.lang.Integer value)
value
belongs to one of the intervals of
this
.value
- the value.true
if value
belongs to one of
the intervals of this
, false
otherwise.@Nullable public java.lang.Integer getGlb()
this
.null
if this multi-interval is empty.@Nullable public java.lang.Integer getLub()
this
.null
if this multi-interval is empty.public int getOrder()
this
, i.e.,
the number of intervals that form this multi-interval.public boolean isUniverse()
this
is the 'universe', i.e. the maximum
representable multi-interval.true
if this
the universe,
false
otherwise.public boolean isSingleton()
true
if this
is a singleton, false
otherwise@NotNull public Interval convexClosure()
this
, i.e. the minimum
convex set containing this
.Interval
corresponding to the convex closure.public boolean subset(@NotNull MultiInterval multiInterval)
this
is a subset of multiInterval
.multiInterval
- the second operand of the inclusion.true
if this
is a subset of
multiInterval
, false
otherwise.@NotNull public MultiInterval complement()
this
with respect to the universe multi-interval.@NotNull public MultiInterval complement(@NotNull MultiInterval universe)
universe
- universe to use for the complement.@NotNull public MultiInterval union(@NotNull MultiInterval multiInterval)
this
and multiInterval
.multiInterval
- the second operand of the union.@NotNull public MultiInterval intersect(@NotNull MultiInterval multiInterval)
this
and multiInterval
.multiInterval
- the second operand of the intersection.@NotNull public MultiInterval diff(@NotNull MultiInterval multiInterval)
this
and multiInterval
.multiInterval
- the second operand of the difference.@NotNull public MultiInterval sum(@NotNull MultiInterval multiInterval)
this
and multiInterval
.multiInterval
- the second operand of the sum.this + multiInterval
@NotNull public MultiInterval sub(@NotNull MultiInterval multiInterval)
this
and multiInterval
.multiInterval
- the second operand of the difference.this - multiInterval
@NotNull public MultiInterval opposite()
@NotNull public java.util.Set<java.lang.Integer> toSet()
Set
representation of this
.this
.@NotNull public MultiInterval clone()
this
.this
.@NotNull public java.lang.String toString()
this
.toString
in class java.lang.Object
this
.public boolean add(@NotNull java.lang.Integer value)
add
in interface java.util.Collection<java.lang.Integer>
add
in interface java.util.Set<java.lang.Integer>
value
- the value to add.true
if the value was not present and was added, false
otherwise.public boolean addAll(@NotNull java.util.Collection<? extends java.lang.Integer> collection)
collection
to the multi-interval.addAll
in interface java.util.Collection<java.lang.Integer>
addAll
in interface java.util.Set<java.lang.Integer>
collection
- collection of integers to add to this
.
It must not contain null
values.true
if at least one (new) element was added, false
otherwise.java.lang.NullPointerException
- if collection
contains null
values.public void clear()
this
becomes the empty set.clear
in interface java.util.Collection<java.lang.Integer>
clear
in interface java.util.Set<java.lang.Integer>
public boolean contains(@NotNull java.lang.Object object)
object
or not.contains
in interface java.util.Collection<java.lang.Integer>
contains
in interface java.util.Set<java.lang.Integer>
object
- object to test.true
if object
is an element (or a subset) of this
, false
otherwise.public boolean containsAll(@NotNull java.util.Collection<?> collection)
collection
.containsAll
in interface java.util.Collection<java.lang.Integer>
containsAll
in interface java.util.Set<java.lang.Integer>
collection
- collection of objects to test.true
if each element of collection
is an element (or subset) of this
,
false
otherwise.public boolean equals(@Nullable java.lang.Object object)
this
is equal to object
.equals
in interface java.util.Collection<java.lang.Integer>
equals
in interface java.util.Set<java.lang.Integer>
equals
in class java.lang.Object
object
- object to test.true
if this
is equal to object
, false
otherwise.public int hashCode()
hashCode
in interface java.util.Collection<java.lang.Integer>
hashCode
in interface java.util.Set<java.lang.Integer>
hashCode
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.Integer>
isEmpty
in interface java.util.Set<java.lang.Integer>
true
if this multi-interval represents the empty set, false
otherwise.@NotNull public java.util.Iterator<java.lang.Integer> iterator()
iterator
in interface java.util.Collection<java.lang.Integer>
iterator
in interface java.lang.Iterable<java.lang.Integer>
iterator
in interface java.util.Set<java.lang.Integer>
public boolean remove(@NotNull java.lang.Object object)
remove
in interface java.util.Collection<java.lang.Integer>
remove
in interface java.util.Set<java.lang.Integer>
object
- element to remove.true
if the element was present and was removed, false
otherwise.java.lang.ClassCastException
- if object
is not an Integer
.public boolean removeAll(@NotNull java.util.Collection<?> collection)
collection
from this
.removeAll
in interface java.util.Collection<java.lang.Integer>
removeAll
in interface java.util.Set<java.lang.Integer>
collection
- collection of elements to remove.true
if the at least one element was present and was removed, false
otherwise.public boolean retainAll(@NotNull java.util.Collection<?> collection)
collection
from this multi-interval.retainAll
in interface java.util.Collection<java.lang.Integer>
retainAll
in interface java.util.Set<java.lang.Integer>
collection
- collection of objects to retain.true
if at least one element was retained, false
otherwise.public int size()
size
in interface java.util.Collection<java.lang.Integer>
size
in interface java.util.Set<java.lang.Integer>
public java.lang.Object[] toArray()
this
.toArray
in interface java.util.Collection<java.lang.Integer>
toArray
in interface java.util.Set<java.lang.Integer>
this
.@NotNull public <T> T[] toArray(@NotNull T[] array)
this
into array
, if it can contain them, otherwise
creates a new array and puts all the integers into it.toArray
in interface java.util.Collection<java.lang.Integer>
toArray
in interface java.util.Set<java.lang.Integer>
T
- type of the elements.array
- array to (possibly) use to store the integers.array
or a new array).