Package com.github.marschall.rangetree
Interface RangeMap<K extends Comparable<? super K>,V>
-
- Type Parameters:
K
- the type of keys in this treeV
- the type of values in this tree
- All Known Implementing Classes:
LLRBRangeTree
,SynchronizedRangeMap
public interface RangeMap<K extends Comparable<? super K>,V>
An object that maps ranges of keys to values. Cannot contain duplicate keys or overlapping ranges.The interface offers a subset of the operations of
Map
with the write operations having instead two keys denoting the inclusive upper and lower bounds of a range.- See Also:
Map
, Range tree
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear()
Removes all mappings from this object.V
computeIfAbsent(K key, Function<? super K,Map.Entry<Range<? extends K>,? extends V>> mappingFunction)
Looks up a value associated with a key.V
get(K key)
Returns the value associated with a key.void
put(K low, K high, V value)
Associates a range of keys with a value.V
putIfAbsent(K low, K high, V value)
Associates a range of keys with a value only if no existing mapping exists.
-
-
-
Method Detail
-
clear
void clear()
Removes all mappings from this object.- See Also:
Map.clear()
-
get
V get(K key)
Returns the value associated with a key.- Parameters:
key
- the key for which to look up a value, notnull
- Returns:
- the value associated with
key
ornull
if not found - Throws:
NullPointerException
- ifkey
isnull
- See Also:
Map.get(Object)
-
computeIfAbsent
V computeIfAbsent(K key, Function<? super K,Map.Entry<Range<? extends K>,? extends V>> mappingFunction)
Looks up a value associated with a key. If none is found the mapping function is applied. If the mapping produces a notnull
value then the mapping is created.- Parameters:
key
- the key for which to look up a value, notnull
mappingFunction
- the mapping function to apply if no value has been found, notnull
- Returns:
- the value associated with
key
ornull
if not found - Throws:
NullPointerException
- ifkey
isnull
NullPointerException
- ifkey
ismappingFunction
- See Also:
Map.computeIfAbsent(Object, Function)
,AbstractMap.SimpleImmutableEntry
-
put
void put(K low, K high, V value)
Associates a range of keys with a value.- Parameters:
low
- the lower end of the range, inclusive, notnull
high
- the upper end of the range, inclusive, notnull
value
- the value to associate, possiblynull
- Throws:
IllegalArgumentException
- if a mapping for a part or the whole range already existsIllegalArgumentException
- iflow
is not less thanhigh
NullPointerException
- iflow
orhigh
arenull
- See Also:
Map.put(Object, Object)
-
putIfAbsent
V putIfAbsent(K low, K high, V value)
Associates a range of keys with a value only if no existing mapping exists.- Parameters:
low
- the lower end of the range, inclusive, notnull
high
- the upper end of the range, inclusive, notnull
value
- the value to associate, possiblynull
- Returns:
- the value mapped to the key range before this method was called
- Throws:
IllegalArgumentException
- iflow
is not less thanhigh
NullPointerException
- iflow
orhigh
arenull
- See Also:
Map.putIfAbsent(Object, Object)
-
-