edu.emory.mathcs.util.collections.ints
Class AbstractIntInterval

java.lang.Object
  extended byedu.emory.mathcs.util.collections.ints.AbstractIntCollection
      extended byedu.emory.mathcs.util.collections.ints.AbstractIntSet
          extended byedu.emory.mathcs.util.collections.ints.AbstractIntSortedSet
              extended byedu.emory.mathcs.util.collections.ints.AbstractIntInterval
All Implemented Interfaces:
IntCollection, IntInterval, IntSet, IntSortedSet
Direct Known Subclasses:
AbstractIntInterval.ConstrainedView, IntCollections.SimpleInterval

public abstract class AbstractIntInterval
extends AbstractIntSortedSet
implements IntInterval

Base class for (possibly mutable) interval classes.

Version:
1.0
Author:
Dawid Kurzyniec

Nested Class Summary
protected static class AbstractIntInterval.ComplementView
           
protected static class AbstractIntInterval.ConstrainedView
           
static class AbstractIntInterval.SimpleIntervalItemIterator
           
static class AbstractIntInterval.SimpleReverseIntervalItemIterator
           
 
Nested classes inherited from class edu.emory.mathcs.util.collections.ints.AbstractIntSortedSet
AbstractIntSortedSet.AbstractComplementSubView, AbstractIntSortedSet.AbstractSubView, AbstractIntSortedSet.ForwardIntervalItemIterator, AbstractIntSortedSet.ReverseIntervalItemIterator
 
Constructor Summary
AbstractIntInterval()
           
 
Method Summary
 boolean addInterval(int first, int last)
          Adds to this set all the numbers between first and last, inclusive, that are not already present in this set and beint to this set's domain.
 int ceiling(int e)
          Returns the smallest number in this set >= e.
 IntInterval ceilingInterval(int 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.
 IntSet complementSet()
          Returns a complement view of this set.
 boolean contains(int e)
          Returns true if this set contains the specified number; false otherwise.
 boolean containsInterval(int first, int 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.
 IntIterator descendingIterator()
          Returns an iterator over numbers in this set, in a decreasing numerical order.
 IntInterval enclosingInterval(int 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.
 int first()
          Returns the smallest number in this set.
 IntInterval firstInterval()
          Returns the first (left-most), widest interval contained in this set, or null if this set is empty.
 int floor(int e)
          Returns the largest number in this set <= e.
 IntInterval floorInterval(int n)
          Returns the largest (right-most), widest interval contained in this set which elements are not all greater than the specified number.
protected abstract  int getFirst()
           
protected abstract  int getLast()
           
 int higher(int e)
          Returns the smallest number in this set > e.
 IntInterval higherInterval(int 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.
 IntIterator iterator()
          Returns an iterator over numbers in this set, in an increasing numerical order.
 int last()
          Returns the largest number in this set.
 IntInterval lastInterval()
          Returns the last (right-most), widest interval contained in this set, or null if this set is empty.
 int lower(int e)
          Returns the largest number in this set < e.
 IntInterval lowerInterval(int n)
          Returns the largest and widest interval contained in this set which all elements are strictly less than the specified number.
 int max()
          The largest number that can be stored in this set.
 int min()
          The smallest number that can be stored in this set.
 int pollFirst()
          Returns and removes the smallest number in this set.
 IntInterval pollFirstInterval()
          Returns and removes the first (left-most), widest interval contained in this set, or null if this set is empty.
 int pollLast()
          Returns and removes the largest number in this set.
 IntInterval pollLastInterval()
          Returns and removes the last (right-most), widest interval contained in this set, or null if this set is empty.
 boolean removeInterval(int first, int last)
          Removes from this set all the numbers between first and last, inclusive.
 boolean retainInterval(int first, int last)
          Retains in this set only the numbers between first and last, inclusive.
 int size64()
          Returns the number of elements in this set.
 IntSortedSet subSet(int first, int 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.ints.AbstractIntSortedSet
headSet, retainAll, tailSet, toCompactString
 
Methods inherited from class edu.emory.mathcs.util.collections.ints.AbstractIntSet
addAll, equals, hashCode, removeAll
 
Methods inherited from class edu.emory.mathcs.util.collections.ints.AbstractIntCollection
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.ints.IntSortedSet
headSet, tailSet, toCompactString
 
Methods inherited from interface edu.emory.mathcs.util.collections.ints.IntSet
add, addAll, containsAll, equals, hashCode, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

AbstractIntInterval

public AbstractIntInterval()
Method Detail

getFirst

protected abstract int getFirst()

getLast

protected abstract int getLast()

min

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

Specified by:
min in interface IntSet
Overrides:
min in class AbstractIntSet

max

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

Specified by:
max in interface IntSet
Overrides:
max in class AbstractIntSet

first

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

Specified by:
first in interface IntSortedSet
Overrides:
first in class AbstractIntSortedSet

last

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

Specified by:
last in interface IntSortedSet
Overrides:
last in class AbstractIntSortedSet

intervalCount

public int intervalCount()
Description copied from interface: IntSortedSet
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 IntSortedSet
Overrides:
intervalCount in class AbstractIntSortedSet

firstInterval

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

Specified by:
firstInterval in interface IntSortedSet
Overrides:
firstInterval in class AbstractIntSortedSet

lastInterval

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

Specified by:
lastInterval in interface IntSortedSet
Overrides:
lastInterval in class AbstractIntSortedSet

lowerInterval

public IntInterval lowerInterval(int n)
Description copied from interface: IntSortedSet
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 IntSortedSet
Returns:
the largest interval smaller than the specified number.

floorInterval

public IntInterval floorInterval(int n)
Description copied from interface: IntSortedSet
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 IntSortedSet
Returns:
the largest interval which lower bound is <= than the specified number.

higherInterval

public IntInterval higherInterval(int n)
Description copied from interface: IntSortedSet
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 IntSortedSet
Returns:
the smallest interval greater than the specified number.

ceilingInterval

public IntInterval ceilingInterval(int n)
Description copied from interface: IntSortedSet
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 IntSortedSet
Returns:
the smallest interval which upper bound is >= than the specified number.

size64

public int size64()
Description copied from interface: IntSet
Returns the number of elements in this set.

Specified by:
size64 in interface IntSet
Overrides:
size64 in class AbstractIntSortedSet

isEmpty

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

Specified by:
isEmpty in interface IntSet
Overrides:
isEmpty in class AbstractIntSortedSet

contains

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

Specified by:
contains in interface IntSet
Overrides:
contains in class AbstractIntCollection

higher

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

Specified by:
higher in interface IntSortedSet
Overrides:
higher in class AbstractIntSortedSet

ceiling

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

Specified by:
ceiling in interface IntSortedSet
Overrides:
ceiling in class AbstractIntSortedSet

lower

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

Specified by:
lower in interface IntSortedSet
Overrides:
lower in class AbstractIntSortedSet

floor

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

Specified by:
floor in interface IntSortedSet
Overrides:
floor in class AbstractIntSortedSet

containsInterval

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

Specified by:
containsInterval in interface IntSet
Overrides:
containsInterval in class AbstractIntSet

enclosingInterval

public IntInterval enclosingInterval(int e)
Description copied from interface: IntSortedSet
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 IntSortedSet
Returns:
the interval containing the specified number.

iterator

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

Specified by:
iterator in interface IntSortedSet
Overrides:
iterator in class AbstractIntSortedSet

descendingIterator

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

Specified by:
descendingIterator in interface IntSortedSet
Overrides:
descendingIterator in class AbstractIntSortedSet

intervalIterator

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

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

descendingIntervalIterator

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

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

clear

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

Specified by:
clear in interface IntSet
Overrides:
clear in class AbstractIntCollection

addInterval

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

Specified by:
addInterval in interface IntSet
Overrides:
addInterval in class AbstractIntSet

removeInterval

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

Specified by:
removeInterval in interface IntSet
Overrides:
removeInterval in class AbstractIntSet

retainInterval

public boolean retainInterval(int first,
                              int last)
Description copied from interface: IntSet
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 IntSet
Overrides:
retainInterval in class AbstractIntSortedSet

pollFirst

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

Specified by:
pollFirst in interface IntSortedSet
Overrides:
pollFirst in class AbstractIntSortedSet

pollLast

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

Specified by:
pollLast in interface IntSortedSet
Overrides:
pollLast in class AbstractIntSortedSet

pollFirstInterval

public IntInterval pollFirstInterval()
Description copied from interface: IntSortedSet
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 IntSortedSet
Overrides:
pollFirstInterval in class AbstractIntSortedSet

pollLastInterval

public IntInterval pollLastInterval()
Description copied from interface: IntSortedSet
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 IntSortedSet
Overrides:
pollLastInterval in class AbstractIntSortedSet

subSet

public IntSortedSet subSet(int first,
                           int last)
Description copied from interface: IntSortedSet
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 IntSortedSet
Parameters:
first - the minimum element of this view (inclusive).
last - the maximum element of this view (inclusive).
Returns:
the subset view

complementSet

public IntSet complementSet()
Description copied from interface: IntSet
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 IntSet
Overrides:
complementSet in class AbstractIntSet

toString

public java.lang.String toString()
Specified by:
toString in interface IntSortedSet
Overrides:
toString in class AbstractIntCollection