edu.emory.mathcs.util.collections.longs
Class AbstractLongInterval

java.lang.Object
  extended byedu.emory.mathcs.util.collections.longs.AbstractLongCollection
      extended byedu.emory.mathcs.util.collections.longs.AbstractLongSet
          extended byedu.emory.mathcs.util.collections.longs.AbstractLongSortedSet
              extended byedu.emory.mathcs.util.collections.longs.AbstractLongInterval
All Implemented Interfaces:
LongCollection, LongInterval, LongSet, LongSortedSet
Direct Known Subclasses:
AbstractLongInterval.ConstrainedView, LongCollections.SimpleInterval

public abstract class AbstractLongInterval
extends AbstractLongSortedSet
implements LongInterval

Base class for (possibly mutable) interval classes.

Version:
1.0
Author:
Dawid Kurzyniec

Nested Class Summary
protected static class AbstractLongInterval.ComplementView
           
protected static class AbstractLongInterval.ConstrainedView
           
static class AbstractLongInterval.SimpleIntervalItemIterator
           
static class AbstractLongInterval.SimpleReverseIntervalItemIterator
           
 
Nested classes inherited from class edu.emory.mathcs.util.collections.longs.AbstractLongSortedSet
AbstractLongSortedSet.AbstractComplementSubView, AbstractLongSortedSet.AbstractSubView, AbstractLongSortedSet.ForwardIntervalItemIterator, AbstractLongSortedSet.ReverseIntervalItemIterator
 
Constructor Summary
AbstractLongInterval()
           
 
Method Summary
 boolean addInterval(long first, long last)
          Adds to this set all the numbers between first and last, inclusive, that are not already present in this set and belong to this set's domain.
 long ceiling(long e)
          Returns the smallest number in this set >= e.
 LongInterval ceilingInterval(long n)
          Returns the smallest (left-most), widest interval contained in this set which elements are not all smaller than the specified number.
 void clear()
          Removes all of the elements from this set.
 LongSet complementSet()
          Returns a complement view of this set.
 boolean contains(long e)
          Returns true if this set contains the specified number; false otherwise.
 boolean containsInterval(long first, long last)
          Returns true if this set contains all the numbers between first and last, inclusive; false otherwise.
 java.util.Iterator descendingIntervalIterator()
          Returns an iterator over intervals of this set, in a decreasing numerical order.
 LongIterator descendingIterator()
          Returns an iterator over numbers in this set, in a decreasing numerical order.
 LongInterval enclosingInterval(long e)
          Returns the widest interval contained in this set that includes the specified number, or null if this set does not include the specified number.
 long first()
          Returns the smallest number in this set.
 LongInterval firstInterval()
          Returns the first (left-most), widest interval contained in this set, or null if this set is empty.
 long floor(long e)
          Returns the largest number in this set <= e.
 LongInterval floorInterval(long n)
          Returns the largest (right-most), widest interval contained in this set which elements are not all greater than the specified number.
protected abstract  long getFirst()
           
protected abstract  long getLast()
           
 long higher(long e)
          Returns the smallest number in this set > e.
 LongInterval higherInterval(long n)
          Returns the smallest (left-most), widest interval contained in this set which all elements are strictly greater than the specified number.
 int intervalCount()
          Returns the minimum count of intervals into which this set can be decomposed.
 java.util.Iterator intervalIterator()
          Returns an iterator over intervals of this set, in an increasing numerical order.
 boolean isEmpty()
          Returns true if this set is empty; false otherwise.
 LongIterator iterator()
          Returns an iterator over numbers in this set, in an increasing numerical order.
 long last()
          Returns the largest number in this set.
 LongInterval lastInterval()
          Returns the last (right-most), widest interval contained in this set, or null if this set is empty.
 long lower(long e)
          Returns the largest number in this set < e.
 LongInterval lowerInterval(long n)
          Returns the largest and widest interval contained in this set which all elements are strictly less than the specified number.
 long max()
          The largest number that can be stored in this set.
 long min()
          The smallest number that can be stored in this set.
 long pollFirst()
          Returns and removes the smallest number in this set.
 LongInterval pollFirstInterval()
          Returns and removes the first (left-most), widest interval contained in this set, or null if this set is empty.
 long pollLast()
          Returns and removes the largest number in this set.
 LongInterval pollLastInterval()
          Returns and removes the last (right-most), widest interval contained in this set, or null if this set is empty.
 boolean removeInterval(long first, long last)
          Removes from this set all the numbers between first and last, inclusive.
 boolean retainInterval(long first, long last)
          Retains in this set only the numbers between first and last, inclusive.
 long size64()
          // PREPROC: Long,Int only Returns the number of elements in this set.
 LongSortedSet subSet(long first, long last)
          A subset view containing all elements from this set between first, inclusive, and last, inclusive.
 java.lang.String toString()
           
 
Methods inherited from class edu.emory.mathcs.util.collections.longs.AbstractLongSortedSet
headSet, retainAll, tailSet, toCompactString
 
Methods inherited from class edu.emory.mathcs.util.collections.longs.AbstractLongSet
addAll, equals, hashCode, removeAll
 
Methods inherited from class edu.emory.mathcs.util.collections.longs.AbstractLongCollection
add, containsAll, remove, size, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.emory.mathcs.util.collections.longs.LongSortedSet
headSet, tailSet, toCompactString
 
Methods inherited from interface edu.emory.mathcs.util.collections.longs.LongSet
add, addAll, containsAll, equals, hashCode, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

AbstractLongInterval

public AbstractLongInterval()
Method Detail

getFirst

protected abstract long getFirst()

getLast

protected abstract long getLast()

min

public long min()
Description copied from interface: LongSet
The smallest number that can be stored in this set.

Specified by:
min in interface LongSet
Overrides:
min in class AbstractLongSet

max

public long max()
Description copied from interface: LongSet
The largest number that can be stored in this set.

Specified by:
max in interface LongSet
Overrides:
max in class AbstractLongSet

first

public long first()
Description copied from interface: LongSortedSet
Returns the smallest number in this set.

Specified by:
first in interface LongSortedSet
Overrides:
first in class AbstractLongSortedSet

last

public long last()
Description copied from interface: LongSortedSet
Returns the largest number in this set.

Specified by:
last in interface LongSortedSet
Overrides:
last in class AbstractLongSortedSet

intervalCount

public int intervalCount()
Description copied from interface: LongSortedSet
Returns the minimum count of intervals into which this set can be decomposed. For instance, {1, 3,4,5, 8,9}.intervalCount() == 3.

Specified by:
intervalCount in interface LongSortedSet
Overrides:
intervalCount in class AbstractLongSortedSet

firstInterval

public LongInterval firstInterval()
Description copied from interface: LongSortedSet
Returns the first (left-most), widest interval contained in this set, or null if this set is empty.

Specified by:
firstInterval in interface LongSortedSet
Overrides:
firstInterval in class AbstractLongSortedSet

lastInterval

public LongInterval lastInterval()
Description copied from interface: LongSortedSet
Returns the last (right-most), widest interval contained in this set, or null if this set is empty.

Specified by:
lastInterval in interface LongSortedSet
Overrides:
lastInterval in class AbstractLongSortedSet

lowerInterval

public LongInterval lowerInterval(long n)
Description copied from interface: LongSortedSet
Returns the largest and widest interval contained in this set which all elements are strictly less than the specified number.

Specified by:
lowerInterval in interface LongSortedSet
Returns:
the largest interval smaller than the specified number.

floorInterval

public LongInterval floorInterval(long n)
Description copied from interface: LongSortedSet
Returns the largest (right-most), widest interval contained in this set which elements are not all greater than the specified number. In other words, it either includes the specified number or has all elements strictly less than the specified number.

Specified by:
floorInterval in interface LongSortedSet
Returns:
the largest interval which lower bound is <= than the specified number.

higherInterval

public LongInterval higherInterval(long n)
Description copied from interface: LongSortedSet
Returns the smallest (left-most), widest interval contained in this set which all elements are strictly greater than the specified number.

Specified by:
higherInterval in interface LongSortedSet
Returns:
the smallest interval greater than the specified number.

ceilingInterval

public LongInterval ceilingInterval(long n)
Description copied from interface: LongSortedSet
Returns the smallest (left-most), widest interval contained in this set which elements are not all smaller than the specified number. In other words, it either includes the specified number or has all elements strictly greater than the specified number.

Specified by:
ceilingInterval in interface LongSortedSet
Returns:
the smallest interval which upper bound is >= than the specified number.

size64

public long size64()
Description copied from interface: LongSet
// PREPROC: Long,Int only Returns the number of elements in this set. // PREPROC: Long,Int only

Specified by:
size64 in interface LongSet
Overrides:
size64 in class AbstractLongSortedSet

isEmpty

public boolean isEmpty()
Description copied from interface: LongSet
Returns true if this set is empty; false otherwise.

Specified by:
isEmpty in interface LongSet
Overrides:
isEmpty in class AbstractLongSortedSet

contains

public boolean contains(long e)
Description copied from interface: LongSet
Returns true if this set contains the specified number; false otherwise.

Specified by:
contains in interface LongSet
Overrides:
contains in class AbstractLongCollection

higher

public long higher(long e)
Description copied from interface: LongSortedSet
Returns the smallest number in this set > e.

Specified by:
higher in interface LongSortedSet
Overrides:
higher in class AbstractLongSortedSet

ceiling

public long ceiling(long e)
Description copied from interface: LongSortedSet
Returns the smallest number in this set >= e.

Specified by:
ceiling in interface LongSortedSet
Overrides:
ceiling in class AbstractLongSortedSet

lower

public long lower(long e)
Description copied from interface: LongSortedSet
Returns the largest number in this set < e.

Specified by:
lower in interface LongSortedSet
Overrides:
lower in class AbstractLongSortedSet

floor

public long floor(long e)
Description copied from interface: LongSortedSet
Returns the largest number in this set <= e.

Specified by:
floor in interface LongSortedSet
Overrides:
floor in class AbstractLongSortedSet

containsInterval

public boolean containsInterval(long first,
                                long last)
Description copied from interface: LongSet
Returns true if this set contains all the numbers between first and last, inclusive; false otherwise.

Specified by:
containsInterval in interface LongSet
Overrides:
containsInterval in class AbstractLongSet

enclosingInterval

public LongInterval enclosingInterval(long e)
Description copied from interface: LongSortedSet
Returns the widest interval contained in this set that includes the specified number, or null if this set does not include the specified number.

Specified by:
enclosingInterval in interface LongSortedSet
Returns:
the interval containing the specified number.

iterator

public LongIterator iterator()
Description copied from interface: LongSortedSet
Returns an iterator over numbers in this set, in an increasing numerical order.

Specified by:
iterator in interface LongSortedSet
Overrides:
iterator in class AbstractLongSortedSet

descendingIterator

public LongIterator descendingIterator()
Description copied from interface: LongSortedSet
Returns an iterator over numbers in this set, in a decreasing numerical order.

Specified by:
descendingIterator in interface LongSortedSet
Overrides:
descendingIterator in class AbstractLongSortedSet

intervalIterator

public java.util.Iterator intervalIterator()
Description copied from interface: LongSortedSet
Returns an iterator over intervals of this set, in an increasing numerical order.

Specified by:
intervalIterator in interface LongSortedSet
Returns:
an iterator over intervals of this set

descendingIntervalIterator

public java.util.Iterator descendingIntervalIterator()
Description copied from interface: LongSortedSet
Returns an iterator over intervals of this set, in a decreasing numerical order.

Specified by:
descendingIntervalIterator in interface LongSortedSet
Returns:
a descending iterator over intervals of this set

clear

public void clear()
Description copied from interface: LongSet
Removes all of the elements from this set. The set will be empty after this call returns.

Specified by:
clear in interface LongSet
Overrides:
clear in class AbstractLongCollection

addInterval

public boolean addInterval(long first,
                           long last)
Description copied from interface: LongSet
Adds to this set all the numbers between first and last, inclusive, that are not already present in this set and belong to this set's domain.

Specified by:
addInterval in interface LongSet
Overrides:
addInterval in class AbstractLongSet

removeInterval

public boolean removeInterval(long first,
                              long last)
Description copied from interface: LongSet
Removes from this set all the numbers between first and last, inclusive.

Specified by:
removeInterval in interface LongSet
Overrides:
removeInterval in class AbstractLongSet

retainInterval

public boolean retainInterval(long first,
                              long last)
Description copied from interface: LongSet
Retains in this set only the numbers between first and last, inclusive. In other words, removes from this set all the numbers outside the specified interval.

Specified by:
retainInterval in interface LongSet
Overrides:
retainInterval in class AbstractLongSortedSet

pollFirst

public long pollFirst()
Description copied from interface: LongSortedSet
Returns and removes the smallest number in this set.

Specified by:
pollFirst in interface LongSortedSet
Overrides:
pollFirst in class AbstractLongSortedSet

pollLast

public long pollLast()
Description copied from interface: LongSortedSet
Returns and removes the largest number in this set.

Specified by:
pollLast in interface LongSortedSet
Overrides:
pollLast in class AbstractLongSortedSet

pollFirstInterval

public LongInterval pollFirstInterval()
Description copied from interface: LongSortedSet
Returns and removes the first (left-most), widest interval contained in this set, or null if this set is empty.

Specified by:
pollFirstInterval in interface LongSortedSet
Overrides:
pollFirstInterval in class AbstractLongSortedSet

pollLastInterval

public LongInterval pollLastInterval()
Description copied from interface: LongSortedSet
Returns and removes the last (right-most), widest interval contained in this set, or null if this set is empty.

Specified by:
pollLastInterval in interface LongSortedSet
Overrides:
pollLastInterval in class AbstractLongSortedSet

subSet

public LongSortedSet subSet(long first,
                            long last)
Description copied from interface: LongSortedSet
A subset view containing all elements from this set between first, inclusive, and last, inclusive. More precisely, the view is narrowed to the domain [min, max]. Hence, complement set of this set will NOT include any elements outside [min, max].

Specified by:
subSet in interface LongSortedSet
Parameters:
first - the minimum element of this view (inclusive).
last - the maximum element of this view (inclusive).
Returns:
the subset view

complementSet

public LongSet complementSet()
Description copied from interface: LongSet
Returns a complement view of this set. Complement view is a set that has the same domain as this set, and consists of all numbers from the domain that are not contained in this set. Changes done to this set are reflected in the complement view after it is created.

Specified by:
complementSet in interface LongSet
Overrides:
complementSet in class AbstractLongSet

toString

public java.lang.String toString()
Specified by:
toString in interface LongSortedSet
Overrides:
toString in class AbstractLongCollection