TKey
- - type of the key. Must implement Comparable.TValue
- - type of the value to associate.public abstract class AbstractIntervalTree<TKey extends java.lang.Comparable<TKey>,TValue>
extends java.lang.Object
Note that this implementation is not thread safe.
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractIntervalTree.EndPoint
Represents a single end point (open, close or both) of a range.
|
class |
AbstractIntervalTree.Entry
Represents a range and a value in this interval tree.
|
protected static class |
AbstractIntervalTree.State |
Modifier and Type | Field and Description |
---|---|
protected java.util.NavigableMap<TKey,AbstractIntervalTree.EndPoint> |
bounds |
Constructor and Description |
---|
AbstractIntervalTree() |
Modifier and Type | Method and Description |
---|---|
protected AbstractIntervalTree.EndPoint |
addEndPoint(TKey key,
TValue value,
AbstractIntervalTree.State state) |
void |
clear()
Remove every interval.
|
boolean |
containsKey(TKey key)
Determines if the given key is within an interval.
|
protected abstract TKey |
decrementKey(TKey key)
Decrement the given key by one unit.
|
java.util.Set<AbstractIntervalTree.Entry> |
entrySet()
Enumerates over every range in this interval tree.
|
TValue |
get(TKey key)
Retrieves the value of the range that matches the given key, or NULL if nothing was found.
|
protected AbstractIntervalTree.EndPoint |
getEndPoint(TKey key)
Get the end-point composite associated with this key.
|
protected abstract TKey |
incrementKey(TKey key)
Increment the given key by one unit.
|
protected void |
onEntryAdded(AbstractIntervalTree.Entry added)
Invoked when an entry is added.
|
protected void |
onEntryRemoved(AbstractIntervalTree.Entry removed)
Invoked when an entry is removed.
|
void |
put(TKey lowerBound,
TKey upperBound,
TValue value)
Associates a given interval of keys with a certain value.
|
void |
putAll(AbstractIntervalTree<TKey,TValue> other)
Inserts every range from the given tree into the current tree.
|
java.util.Set<AbstractIntervalTree.Entry> |
remove(TKey lowerBound,
TKey upperBound)
Removes every interval that intersects with the given range.
|
java.util.Set<AbstractIntervalTree.Entry> |
remove(TKey lowerBound,
TKey upperBound,
boolean preserveDifference)
Removes every interval that intersects with the given range.
|
protected java.util.NavigableMap<TKey extends java.lang.Comparable<TKey>,AbstractIntervalTree.EndPoint> bounds
public java.util.Set<AbstractIntervalTree.Entry> remove(TKey lowerBound, TKey upperBound)
lowerBound
- - lowest value to remove.upperBound
- - highest value to remove.public java.util.Set<AbstractIntervalTree.Entry> remove(TKey lowerBound, TKey upperBound, boolean preserveDifference)
lowerBound
- - lowest value to remove.upperBound
- - highest value to remove.preserveOutside
- - whether or not to preserve the intervals that are partially outside.protected AbstractIntervalTree.EndPoint addEndPoint(TKey key, TValue value, AbstractIntervalTree.State state)
public void put(TKey lowerBound, TKey upperBound, TValue value)
Overlapping intervals are not permitted. A key can only be associated with a single value.
lowerBound
- - the minimum key (inclusive).upperBound
- - the maximum key (inclusive).value
- - the value, or NULL to reset this range.public boolean containsKey(TKey key)
key
- - key to check.public java.util.Set<AbstractIntervalTree.Entry> entrySet()
public void clear()
public void putAll(AbstractIntervalTree<TKey,TValue> other)
other
- - the other tree to read from.public TValue get(TKey key)
key
- - the level to read for.protected AbstractIntervalTree.EndPoint getEndPoint(TKey key)
key
- - key to search for.protected void onEntryAdded(AbstractIntervalTree.Entry added)
added
- - the entry that was added.protected void onEntryRemoved(AbstractIntervalTree.Entry removed)
removed
- - the removed entry.protected abstract TKey decrementKey(TKey key)
key
- - the key that should be decremented.