Package it.unimi.dsi.util
Class Interval
- All Implemented Interfaces:
IntBidirectionalIterable,IntCollection,IntIterable,IntSet,IntSortedSet,Serializable,Cloneable,Iterable<Integer>,Collection<Integer>,Set<Integer>,SortedSet<Integer>
public final class Interval extends AbstractIntSortedSet implements IntSortedSet, Serializable
An interval of integers. An interval is defined
by two integers, called its
left and right
extremes, and contains all integers x such that
left ≤ x ≤ right.
This class has no constructor: use the static factory methods
valueOf(int, int) and valueOf(int), instead.
Instances of this class are immutable, and moreover implement
the IntSortedSet interface. The
equality method allows to check equality with
both sorted and non-sorted sets of integers.
To reduce garbage collection, intervals made of one non-negative small points are precomputed and returned upon request.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedInterval(int left, int right)Builds an interval with given extremes. -
Method Summary
Modifier and Type Method Description IntComparatorcomparator()intcompareTo(int x)Compares this interval to an integer.intcompareTo(int x, int radius)Compares this interval to an integer with a specified radius.intcompareTo(int x, int leftRadius, int rightRadius)Compares this interval to an integer with specified left and right radii.booleancontains(int x)Checks whether this interval contains the specified integer.booleancontains(int x, int radius)Checks whether this interval would contain the specified integer if enlarged in both directions by the specified radius.booleancontains(int x, int leftRadius, int rightRadius)Checks whether this interval would contain the specified integer if enlarged in each direction with the respective radius.booleancontains(Interval interval)Checks whether this interval contains the specified interval.booleanequals(Object o)Checks whether this interval is equal to another set of integers.intfirstInt()inthashCode()IntSortedSetheadSet(int to)IntBidirectionalIteratoriterator()Returns an iterator over the integers in this interval.IntBidirectionalIteratoriterator(int from)Returns an iterator over the integers in this interval larger than or equal to a given integer.intlastInt()intlength()Returns the interval length, that is, the number of integers contained in the interval.intsize()An alias forlength().IntSortedSetsubSet(int from, int to)IntSortedSettailSet(int from)StringtoString()static IntervalvalueOf(int point)Returns a one-point interval.static IntervalvalueOf(int left, int right)Returns an interval with given extremes.Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntCollection
add, add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toIntArray, toIntArrayMethods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface it.unimi.dsi.fastutil.ints.IntCollection
add, addAll, containsAll, removeAll, removeIf, removeIf, retainAll, toArray, toIntArray, toIntArrayMethods inherited from interface it.unimi.dsi.fastutil.ints.IntSet
add, contains, rem, remove, removeMethods inherited from interface it.unimi.dsi.fastutil.ints.IntSortedSet
first, headSet, last, subSet, tailSet
-
Field Details
-
Constructor Details
-
Interval
protected Interval(int left, int right)Builds an interval with given extremes.You cannot generate an empty interval with this constructor. Use
Intervals.EMPTY_INTERVALinstead.- Parameters:
left- the left extreme.right- the right extreme (which must be greater than or equal to the left extreme).
-
-
Method Details
-
valueOf
Returns an interval with given extremes.You cannot obtain an empty interval with this factory method. Use
Intervals.EMPTY_INTERVALinstead.- Parameters:
left- the left extreme.right- the right extreme (which must be greater than or equal to the left extreme).- Returns:
- an interval with the given extremes.
-
valueOf
Returns a one-point interval.You cannot obtain an empty interval with this factory method. Use
Intervals.EMPTY_INTERVALinstead.- Parameters:
point- a point.- Returns:
- a one-point interval
-
length
public int length()Returns the interval length, that is, the number of integers contained in the interval.- Returns:
- the interval length.
-
size
public int size()An alias forlength().- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceSet<Integer>- Specified by:
sizein classAbstractCollection<Integer>- Returns:
- the interval length.
-
iterator
Returns an iterator over the integers in this interval.- Specified by:
iteratorin interfaceCollection<Integer>- Specified by:
iteratorin interfaceIntBidirectionalIterable- Specified by:
iteratorin interfaceIntCollection- Specified by:
iteratorin interfaceIntIterable- Specified by:
iteratorin interfaceIntSet- Specified by:
iteratorin interfaceIntSortedSet- Specified by:
iteratorin interfaceIterable<Integer>- Specified by:
iteratorin interfaceSet<Integer>- Specified by:
iteratorin classAbstractIntSortedSet- Returns:
- an integer iterator over the elements in this interval.
-
iterator
Returns an iterator over the integers in this interval larger than or equal to a given integer.- Specified by:
iteratorin interfaceIntSortedSet- Parameters:
from- the starting integer.- Returns:
- an integer iterator over the elements in this interval.
-
contains
public boolean contains(int x)Checks whether this interval contains the specified integer.- Specified by:
containsin interfaceIntCollection- Overrides:
containsin classAbstractIntCollection- Parameters:
x- an integer.- Returns:
- whether this interval contains
x, that is, whetherleft≤x≤right.
-
contains
Checks whether this interval contains the specified interval.- Parameters:
interval- an interval.- Returns:
- whether this interval contains (as a set)
interval.
-
contains
public boolean contains(int x, int radius)Checks whether this interval would contain the specified integer if enlarged in both directions by the specified radius. -
contains
public boolean contains(int x, int leftRadius, int rightRadius)Checks whether this interval would contain the specified integer if enlarged in each direction with the respective radius. directions by the specified radius. -
compareTo
public int compareTo(int x)Compares this interval to an integer. -
compareTo
public int compareTo(int x, int radius)Compares this interval to an integer with a specified radius. -
compareTo
public int compareTo(int x, int leftRadius, int rightRadius)Compares this interval to an integer with specified left and right radii.- Parameters:
x- an integer.leftRadius- the left radius.rightRadius- the right radius.- Returns:
- a negative integer, zero, or a positive integer as
xis positioned at the left, belongs, or is positioned to the right of this interval enlarged byleftRadiuson the left andrightRadiusin the right, that is, asx<left−leftRadius,left−leftRadius≤x≤right+rightRadiusorright+rightRadius<x.
-
comparator
- Specified by:
comparatorin interfaceIntSortedSet- Specified by:
comparatorin interfaceSortedSet<Integer>
-
headSet
- Specified by:
headSetin interfaceIntSortedSet
-
tailSet
- Specified by:
tailSetin interfaceIntSortedSet
-
subSet
- Specified by:
subSetin interfaceIntSortedSet
-
firstInt
public int firstInt()- Specified by:
firstIntin interfaceIntSortedSet
-
lastInt
public int lastInt()- Specified by:
lastIntin interfaceIntSortedSet
-
toString
- Overrides:
toStringin classAbstractIntCollection
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Integer>- Specified by:
hashCodein interfaceSet<Integer>- Overrides:
hashCodein classAbstractIntSet
-
equals
Checks whether this interval is equal to another set of integers.- Specified by:
equalsin interfaceCollection<Integer>- Specified by:
equalsin interfaceSet<Integer>- Overrides:
equalsin classAbstractIntSet- Parameters:
o- an object.- Returns:
- true if
ois an ordered set of integer containing the same element of this interval in the same order, or ifois a set of integers containing the same elements of this interval.
-