Package com.github.marschall.rangetree
Class SynchronizedRangeMap<K extends Comparable<? super K>,V>
- java.lang.Object
-
- com.github.marschall.rangetree.SynchronizedRangeMap<K,V>
-
- Type Parameters:
K
- the type of keys in this treeV
- the type of values in this tree
- All Implemented Interfaces:
RangeMap<K,V>
public final class SynchronizedRangeMap<K extends Comparable<? super K>,V> extends Object implements RangeMap<K,V>
Adds synchronization around aRangeMap
.
-
-
Constructor Summary
Constructors Constructor Description SynchronizedRangeMap(RangeMap<K,V> delegate)
Constructs a newSynchronizedRangeMap
.
-
Method Summary
All Methods Instance Methods Concrete 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.
-
-
-
Constructor Detail
-
SynchronizedRangeMap
public SynchronizedRangeMap(RangeMap<K,V> delegate)
Constructs a newSynchronizedRangeMap
.- Parameters:
delegate
- the delegate to wrap, notnull
- Throws:
NullPointerException
- ifdelegate
isnull
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:RangeMap
Removes all mappings from this object.- Specified by:
clear
in interfaceRangeMap<K extends Comparable<? super K>,V>
- See Also:
Map.clear()
-
get
public V get(K key)
Description copied from interface:RangeMap
Returns the value associated with a key.- Specified by:
get
in interfaceRangeMap<K extends Comparable<? super K>,V>
- Parameters:
key
- the key for which to look up a value, notnull
- Returns:
- the value associated with
key
ornull
if not found - See Also:
Map.get(Object)
-
computeIfAbsent
public V computeIfAbsent(K key, Function<? super K,Map.Entry<Range<? extends K>,? extends V>> mappingFunction)
Description copied from interface:RangeMap
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.- Specified by:
computeIfAbsent
in interfaceRangeMap<K extends Comparable<? super K>,V>
- 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 - See Also:
Map.computeIfAbsent(Object, Function)
,AbstractMap.SimpleImmutableEntry
-
put
public void put(K low, K high, V value)
Description copied from interface:RangeMap
Associates a range of keys with a value.- Specified by:
put
in interfaceRangeMap<K extends Comparable<? super K>,V>
- 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
- See Also:
Map.put(Object, Object)
-
putIfAbsent
public V putIfAbsent(K low, K high, V value)
Description copied from interface:RangeMap
Associates a range of keys with a value only if no existing mapping exists.- Specified by:
putIfAbsent
in interfaceRangeMap<K extends Comparable<? super K>,V>
- 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
- See Also:
Map.putIfAbsent(Object, Object)
-
-