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 voidclear()Removes all mappings from this object.VcomputeIfAbsent(K key, Function<? super K,Map.Entry<Range<? extends K>,? extends V>> mappingFunction)Looks up a value associated with a key.Vget(K key)Returns the value associated with a key.voidput(K low, K high, V value)Associates a range of keys with a value.VputIfAbsent(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- ifdelegateisnull
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:RangeMapRemoves all mappings from this object.- Specified by:
clearin interfaceRangeMap<K extends Comparable<? super K>,V>- See Also:
Map.clear()
-
get
public V get(K key)
Description copied from interface:RangeMapReturns the value associated with a key.- Specified by:
getin interfaceRangeMap<K extends Comparable<? super K>,V>- Parameters:
key- the key for which to look up a value, notnull- Returns:
- the value associated with
keyornullif 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:RangeMapLooks up a value associated with a key. If none is found the mapping function is applied. If the mapping produces a notnullvalue then the mapping is created.- Specified by:
computeIfAbsentin interfaceRangeMap<K extends Comparable<? super K>,V>- Parameters:
key- the key for which to look up a value, notnullmappingFunction- the mapping function to apply if no value has been found, notnull- Returns:
- the value associated with
keyornullif not found - See Also:
Map.computeIfAbsent(Object, Function),AbstractMap.SimpleImmutableEntry
-
put
public void put(K low, K high, V value)
Description copied from interface:RangeMapAssociates a range of keys with a value.- Specified by:
putin interfaceRangeMap<K extends Comparable<? super K>,V>- Parameters:
low- the lower end of the range, inclusive, notnullhigh- the upper end of the range, inclusive, notnullvalue- 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:RangeMapAssociates a range of keys with a value only if no existing mapping exists.- Specified by:
putIfAbsentin interfaceRangeMap<K extends Comparable<? super K>,V>- Parameters:
low- the lower end of the range, inclusive, notnullhigh- the upper end of the range, inclusive, notnullvalue- the value to associate, possiblynull- Returns:
- the value mapped to the key range before this method was called
- See Also:
Map.putIfAbsent(Object, Object)
-
-