it.unimi.dsi.util
Class LongInterval

java.lang.Object
  extended by java.util.AbstractCollection<Long>
      extended by it.unimi.dsi.fastutil.longs.AbstractLongCollection
          extended by it.unimi.dsi.fastutil.longs.AbstractLongSet
              extended by it.unimi.dsi.fastutil.longs.AbstractLongSortedSet
                  extended by it.unimi.dsi.util.LongInterval
All Implemented Interfaces:
LongCollection, LongIterable, LongSet, LongSortedSet, Serializable, Cloneable, Iterable<Long>, Collection<Long>, Set<Long>, SortedSet<Long>

public final class LongInterval
extends AbstractLongSortedSet
implements LongSortedSet, Serializable

An interval of longs. See Interval for details.

See Also:
Serialized Form

Field Summary
 long left
          The left extreme of the interval.
 long right
          The right extreme of the interval.
 
Constructor Summary
protected LongInterval(long left, long right)
          Builds an interval with given extremes.
 
Method Summary
 LongComparator comparator()
           
 int compareTo(int x)
          Compares this interval to an integer.
 int compareTo(int x, int radius)
          Compares this interval to an integer with a specified radius.
 int compareTo(int x, int leftRadius, int rightRadius)
          Compares this interval to an integer with specified left and right radii.
 boolean contains(int x)
          Checks whether this interval contains the specified integer.
 boolean contains(int x, int radius)
          Checks whether this interval would contain the specified integer if enlarged in both directions by the specified radius.
 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.
 boolean contains(LongInterval interval)
          Checks whether this interval contains the specified interval.
 boolean equals(Object o)
          Checks whether this interval is equal to another set of integers.
 long firstLong()
           
 int hashCode()
           
 LongSortedSet headSet(long to)
           
 LongBidirectionalIterator iterator()
          Returns an iterator over the integers in this interval.
 LongBidirectionalIterator iterator(long from)
          Returns an iterator over the integers in this interval larger than or equal to a given integer.
 long lastLong()
           
 long length()
          Returns the interval length, that is, the number of integers contained in the interval.
 int size()
          An alias for length() miminised with Integer.MAX_VALUE.
 long size64()
          An alias for length().
 LongSortedSet subSet(long from, long to)
           
 LongSortedSet tailSet(long from)
           
 String toString()
           
static LongInterval valueOf(long point)
          Returns a one-point interval.
static LongInterval valueOf(long left, long right)
          Returns an interval with given extremes.
 
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongSortedSet
first, headSet, last, longIterator, subSet, tailSet
 
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongSet
rem, remove, remove
 
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongCollection
add, add, addAll, addAll, contains, contains, containsAll, containsAll, isEmpty, rem, removeAll, removeAll, retainAll, retainAll, toArray, toArray, toArray, toLongArray, toLongArray
 
Methods inherited from class java.util.AbstractCollection
clear
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongSortedSet
headSet, longIterator, subSet, tailSet
 
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongSet
remove
 
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongCollection
add, addAll, contains, containsAll, rem, removeAll, retainAll, toArray, toArray, toLongArray, toLongArray
 
Methods inherited from interface java.util.SortedSet
first, last
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

left

public final long left
The left extreme of the interval.


right

public final long right
The right extreme of the interval.

Constructor Detail

LongInterval

protected LongInterval(long left,
                       long right)
Builds an interval with given extremes.

You cannot generate an empty interval with this constructor. Use Intervals.EMPTY_INTERVAL instead.

Parameters:
left - the left extreme.
right - the right extreme (which must be greater than or equal to the left extreme).
Method Detail

valueOf

public static LongInterval valueOf(long left,
                                   long right)
Returns an interval with given extremes.

You cannot obtain an empty interval with this factory method. Use Intervals.EMPTY_INTERVAL instead.

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

public static LongInterval valueOf(long point)
Returns a one-point interval.

You cannot obtain an empty interval with this factory method. Use Intervals.EMPTY_INTERVAL instead.

Parameters:
point - a point.
Returns:
a one-point interval

length

public long 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 for length() miminised with Integer.MAX_VALUE.

Specified by:
size in interface Collection<Long>
Specified by:
size in interface Set<Long>
Specified by:
size in class AbstractCollection<Long>
Returns:
the interval length minimised with Integer.MAX_VALUE.

size64

public long size64()
An alias for length().

Returns:
the interval length.

iterator

public LongBidirectionalIterator iterator()
Returns an iterator over the integers in this interval.

Specified by:
iterator in interface LongCollection
Specified by:
iterator in interface LongIterable
Specified by:
iterator in interface LongSet
Specified by:
iterator in interface LongSortedSet
Specified by:
iterator in interface Iterable<Long>
Specified by:
iterator in interface Collection<Long>
Specified by:
iterator in interface Set<Long>
Overrides:
iterator in class AbstractLongSortedSet
Returns:
an integer iterator over the elements in this interval.

iterator

public LongBidirectionalIterator iterator(long from)
Returns an iterator over the integers in this interval larger than or equal to a given integer.

Specified by:
iterator in interface LongSortedSet
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.

Parameters:
x - an integer.
Returns:
whether this interval contains x, that is, whether leftxright.

contains

public boolean contains(LongInterval interval)
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.

Parameters:
x - an integer.
radius - the radius.
Returns:
whether this interval enlarged by radius would contain x, e.g., whether leftradiusxright+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.

Parameters:
x - an integer.
leftRadius - the left radius.
rightRadius - the right radius.
Returns:
whether this interval enlarged to the left by leftRadius and to the right by rightRadius would contain x, e.g., whether leftleftRadiusxright+rightRadius.

compareTo

public int compareTo(int x)
Compares this interval to an integer.

Parameters:
x - an integer.
Returns:
a negative integer, zero, or a positive integer as x is positioned at the left, belongs, or is positioned to the right of this interval, e.g., as x < left, leftxright or right < x.

compareTo

public int compareTo(int x,
                     int radius)
Compares this interval to an integer with a specified radius.

Parameters:
x - an integer.
radius - the radius.
Returns:
a negative integer, zero, or a positive integer as x is positioned at the left, belongs, or is positioned to the right of this interval enlarged by radius, that is, as x < leftradius, leftradiusxright+radius or right+radius < x.

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 x is positioned at the left, belongs, or is positioned to the right of this interval enlarged by leftRadius on the left and rightRadius in the right, that is, as x < leftleftRadius, leftleftRadiusxright+rightRadius or right+rightRadius < x.

comparator

public LongComparator comparator()
Specified by:
comparator in interface LongSortedSet
Specified by:
comparator in interface SortedSet<Long>

headSet

public LongSortedSet headSet(long to)
Specified by:
headSet in interface LongSortedSet

tailSet

public LongSortedSet tailSet(long from)
Specified by:
tailSet in interface LongSortedSet

subSet

public LongSortedSet subSet(long from,
                            long to)
Specified by:
subSet in interface LongSortedSet

firstLong

public long firstLong()
Specified by:
firstLong in interface LongSortedSet

lastLong

public long lastLong()
Specified by:
lastLong in interface LongSortedSet

toString

public String toString()
Overrides:
toString in class AbstractLongCollection

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<Long>
Specified by:
hashCode in interface Set<Long>
Overrides:
hashCode in class AbstractLongSet

equals

public boolean equals(Object o)
Checks whether this interval is equal to another set of integers.

Specified by:
equals in interface Collection<Long>
Specified by:
equals in interface Set<Long>
Overrides:
equals in class AbstractLongSet
Parameters:
o - an object.
Returns:
true if o is an ordered set of integer containing the same element of this interval in the same order, or if o is a set of integers containing the same elements of this interval.