edu.emory.mathcs.util.collections.shorts
Class AbstractShortInterval

java.lang.Object
  extended byedu.emory.mathcs.util.collections.shorts.AbstractShortCollection
      extended byedu.emory.mathcs.util.collections.shorts.AbstractShortSet
          extended byedu.emory.mathcs.util.collections.shorts.AbstractShortSortedSet
              extended byedu.emory.mathcs.util.collections.shorts.AbstractShortInterval
All Implemented Interfaces:
ShortCollection, ShortInterval, ShortSet, ShortSortedSet
Direct Known Subclasses:
AbstractShortInterval.ConstrainedView, ShortCollections.SimpleInterval

public abstract class AbstractShortInterval
extends AbstractShortSortedSet
implements ShortInterval

Base class for (possibly mutable) interval classes.

Version:
1.0
Author:
Dawid Kurzyniec

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

Constructor Detail

AbstractShortInterval

public AbstractShortInterval()
Method Detail

getFirst

protected abstract short getFirst()

getLast

protected abstract short getLast()

min

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

Specified by:
min in interface ShortSet
Overrides:
min in class AbstractShortSet

max

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

Specified by:
max in interface ShortSet
Overrides:
max in class AbstractShortSet

first

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

Specified by:
first in interface ShortSortedSet
Overrides:
first in class AbstractShortSortedSet

last

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

Specified by:
last in interface ShortSortedSet
Overrides:
last in class AbstractShortSortedSet

intervalCount

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

firstInterval

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

Specified by:
firstInterval in interface ShortSortedSet
Overrides:
firstInterval in class AbstractShortSortedSet

lastInterval

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

Specified by:
lastInterval in interface ShortSortedSet
Overrides:
lastInterval in class AbstractShortSortedSet

lowerInterval

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

floorInterval

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

higherInterval

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

ceilingInterval

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

size

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

Specified by:
size in interface ShortSet
Overrides:
size in class AbstractShortSortedSet

isEmpty

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

Specified by:
isEmpty in interface ShortSet
Overrides:
isEmpty in class AbstractShortSortedSet

contains

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

Specified by:
contains in interface ShortSet
Overrides:
contains in class AbstractShortCollection

higher

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

Specified by:
higher in interface ShortSortedSet
Overrides:
higher in class AbstractShortSortedSet

ceiling

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

Specified by:
ceiling in interface ShortSortedSet
Overrides:
ceiling in class AbstractShortSortedSet

lower

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

Specified by:
lower in interface ShortSortedSet
Overrides:
lower in class AbstractShortSortedSet

floor

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

Specified by:
floor in interface ShortSortedSet
Overrides:
floor in class AbstractShortSortedSet

containsInterval

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

Specified by:
containsInterval in interface ShortSet
Overrides:
containsInterval in class AbstractShortSet

enclosingInterval

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

iterator

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

Specified by:
iterator in interface ShortSortedSet
Overrides:
iterator in class AbstractShortSortedSet

descendingIterator

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

Specified by:
descendingIterator in interface ShortSortedSet
Overrides:
descendingIterator in class AbstractShortSortedSet

intervalIterator

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

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

descendingIntervalIterator

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

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

clear

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

Specified by:
clear in interface ShortSet
Overrides:
clear in class AbstractShortCollection

addInterval

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

Specified by:
addInterval in interface ShortSet
Overrides:
addInterval in class AbstractShortSet

removeInterval

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

Specified by:
removeInterval in interface ShortSet
Overrides:
removeInterval in class AbstractShortSet

retainInterval

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

pollFirst

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

Specified by:
pollFirst in interface ShortSortedSet
Overrides:
pollFirst in class AbstractShortSortedSet

pollLast

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

Specified by:
pollLast in interface ShortSortedSet
Overrides:
pollLast in class AbstractShortSortedSet

pollFirstInterval

public ShortInterval pollFirstInterval()
Description copied from interface: ShortSortedSet
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 ShortSortedSet
Overrides:
pollFirstInterval in class AbstractShortSortedSet

pollLastInterval

public ShortInterval pollLastInterval()
Description copied from interface: ShortSortedSet
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 ShortSortedSet
Overrides:
pollLastInterval in class AbstractShortSortedSet

subSet

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

complementSet

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

toString

public java.lang.String toString()
Specified by:
toString in interface ShortSortedSet
Overrides:
toString in class AbstractShortCollection