Class SynchronizedDoubleKeyHashMap<Key1,Key2,Value>
- java.lang.Object
-
- jetbrains.buildServer.util.AbstractDoubleKeyMap<Key1,Key2,Value>
-
- jetbrains.buildServer.util.DoubleKeyHashMap<Key1,Key2,Value>
-
- jetbrains.buildServer.util.SynchronizedDoubleKeyHashMap<Key1,Key2,Value>
-
- All Implemented Interfaces:
DoubleKeyMap<Key1,Key2,Value>
public class SynchronizedDoubleKeyHashMap<Key1,Key2,Value> extends DoubleKeyHashMap<Key1,Key2,Value>
A thread-safe double key map.- Since:
- 8.1
- Author:
- Maxim Podkolzine (maxim.podkolzine@jetbrains.com)
- See Also:
DoubleKeyMap,DoubleKeyHashMap
-
-
Field Summary
-
Fields inherited from class jetbrains.buildServer.util.AbstractDoubleKeyMap
myMapByKey1, myMapByKey2, mySize
-
-
Constructor Summary
Constructors Constructor Description SynchronizedDoubleKeyHashMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the map.booleancontains(Key1 k1, Key2 k2)Returns whether the map contains a value for the key pair(k1, k2).booleancontainsAnyByKey1(Key1 k1)Returns whether the map contains any value for the specified first keyk1.booleancontainsAnyByKey2(Key2 k2)Returns whether the map contains any value for the specified second keyk2.Set<Map.Entry<Key1,Map<Key2,Value>>>entrySet()Returns a set view of the map entries in a form(key1, key2 -> value).Set<Map.Entry<Key2,Value>>entrySetByKey1(Key1 k1)Returns a set view of the map slice by the specified first keyk1.Set<Map.Entry<Key1,Value>>entrySetByKey2(Key2 k2)Returns a set view of the map slice by the specified second keyk2.Valueget(Key1 k1, Key2 k2)Returns the value corresponding to the key pair(k1, k2).Map<Key2,Value>getAllByKey1(Key1 k1)Returns the map slice by the first keyk1specified.Map<Key1,Value>getAllByKey2(Key2 k2)Returns the map slice by the second keyk2specified.Map<Key1,Set<Key2>>keys()Returns all the keys of this map in a formkey1 -> {key2}.Set<Key2>keySet1(Key1 k1)Returns the key set of the map slice by the specified first keyk1.Set<Key1>keySet2(Key2 k2)Returns the key set of the map slice by the specified second keyk2.Valueput(Key1 k1, Key2 k2, Value v)Adds the triple to the map, overwrites existing one if present.voidputAll(DoubleKeyMap<Key1,Key2,Value> map)Adds anotherDoubleKeyMapto this map.voidputAllForKey1(Key1 k1, Map<Key2,Value> map)Adds the bunch of values to the map, overwriting existing ones if present.voidputAllForKey2(Key2 k2, Map<Key1,Value> map)Adds the bunch of values to the map, overwriting existing ones if present.Valueremove(Key1 k1, Key2 k2)Removes the value from the map corresponding to the keys pair(k1, k2)(if present).voidremoveAll(Collection<Key1> keys1, Collection<Key2> keys2)Removes the whole sector covered by the key setskeys1andkey2).Map<Key2,Value>removeAllByKey1(Key1 k1)Removes all values from the map corresponding to the first keyk1(if present).Map<Key1,Value>removeAllByKey2(Key2 k2)Removes all values from the map corresponding to the second keyk2(if present).Collection<Value>values()Returns a collection of values of this map.Collection<Value>valuesByKey1(Key1 k1)Returns the values collection of the map slice by the specified first keyk1.Collection<Value>valuesByKey2(Key2 k2)Returns the values collection of the map slice by the specified second keyk2.-
Methods inherited from class jetbrains.buildServer.util.AbstractDoubleKeyMap
isEmpty, recalculateSize, size
-
-
-
-
Method Detail
-
put
@Nullable public Value put(@NotNull Key1 k1, @NotNull Key2 k2, @Nullable Value v)
Description copied from interface:DoubleKeyMapAdds the triple to the map, overwrites existing one if present.Uses the constant number of ordinary map operations (
getandput).- Specified by:
putin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
putin classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first keyk2- second keyv- the value (can benull).- Returns:
- previous value for the
(k1, k2)
-
putAllForKey1
public void putAllForKey1(@NotNull Key1 k1, @NotNull Map<Key2,Value> map)Description copied from interface:DoubleKeyMapAdds the bunch of values to the map, overwriting existing ones if present. More precisely, this method adds the entries(k1, k2, v), where(k2, v)are all mappings of the specifiedmap.Works in a linear time of input
mapsize.- Specified by:
putAllForKey1in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
putAllForKey1in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first keymap- the second key based map
-
putAllForKey2
public void putAllForKey2(@NotNull Key2 k2, @NotNull Map<Key1,Value> map)Description copied from interface:DoubleKeyMapAdds the bunch of values to the map, overwriting existing ones if present. More precisely, this method adds the entries(k1, k2, v), where(k1, v)are all mappings of the specifiedmap.Works in a linear time of input
mapsize.- Specified by:
putAllForKey2in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
putAllForKey2in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k2- second keymap- the second key based map
-
putAll
public void putAll(@NotNull DoubleKeyMap<Key1,Key2,Value> map)Description copied from interface:DoubleKeyMapAdds anotherDoubleKeyMapto this map.The values with same key pairs are overwritten.
- Specified by:
putAllin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
putAllin classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
map- the map
-
get
@Nullable public Value get(@NotNull Key1 k1, @NotNull Key2 k2)
Description copied from interface:DoubleKeyMapReturns the value corresponding to the key pair(k1, k2).Uses the constant number of ordinary map operations (
get).- Specified by:
getin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
getin classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first keyk2- second key- Returns:
- the value if present, or
null.
-
getAllByKey1
@NotNull public Map<Key2,Value> getAllByKey1(@NotNull Key1 k1)
Description copied from interface:DoubleKeyMapReturns the map slice by the first keyk1specified. For all triples(k1, k2) -> valuea mapk2 -> valuewith fixedk1is returned.Result map can be empty, but never
null.Uses the constant number of ordinary map operations (
get).- Specified by:
getAllByKey1in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
getAllByKey1in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first key- Returns:
- map slice by the first key
-
getAllByKey2
@NotNull public Map<Key1,Value> getAllByKey2(@NotNull Key2 k2)
Description copied from interface:DoubleKeyMapReturns the map slice by the second keyk2specified. For all triples(k1, k2) -> valuea mapk1 -> valuewith fixedk2is returned.Result map can be empty, but never
null.Uses the constant number of ordinary map operations (
get).- Specified by:
getAllByKey2in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
getAllByKey2in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k2- second key- Returns:
- map slice by the second key
-
contains
public boolean contains(@NotNull Key1 k1, @NotNull Key2 k2)Description copied from interface:DoubleKeyMapReturns whether the map contains a value for the key pair(k1, k2).Uses the constant number of ordinary map operations (
get).- Specified by:
containsin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
containsin classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first keyk2- second key- Returns:
- true if there is a value for the
(k1, k2)pair.
-
containsAnyByKey1
public boolean containsAnyByKey1(@NotNull Key1 k1)Description copied from interface:DoubleKeyMapReturns whether the map contains any value for the specified first keyk1.Uses the constant number of ordinary map operations (
get).- Specified by:
containsAnyByKey1in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
containsAnyByKey1in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first key- Returns:
- true if there is a value for the first key
-
containsAnyByKey2
public boolean containsAnyByKey2(@NotNull Key2 k2)Description copied from interface:DoubleKeyMapReturns whether the map contains any value for the specified second keyk2.Uses the constant number of ordinary map operations (
get).- Specified by:
containsAnyByKey2in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
containsAnyByKey2in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k2- second key- Returns:
- true if there is a value for the second key
-
entrySet
@NotNull public Set<Map.Entry<Key1,Map<Key2,Value>>> entrySet()
Description copied from interface:DoubleKeyMapReturns a set view of the map entries in a form(key1, key2 -> value).Works in a constant time (
O(1)).- Specified by:
entrySetin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
entrySetin classAbstractDoubleKeyMap<Key1,Key2,Value>- Returns:
- a set view of the mappings contained in this map
-
entrySetByKey1
@NotNull public Set<Map.Entry<Key2,Value>> entrySetByKey1(@NotNull Key1 k1)
Description copied from interface:DoubleKeyMapReturns a set view of the map slice by the specified first keyk1.Uses the constant number of ordinary map operations (
get).- Specified by:
entrySetByKey1in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
entrySetByKey1in classAbstractDoubleKeyMap<Key1,Key2,Value>- Returns:
- a set view of the map slice by the first key
-
entrySetByKey2
@NotNull public Set<Map.Entry<Key1,Value>> entrySetByKey2(@NotNull Key2 k2)
Description copied from interface:DoubleKeyMapReturns a set view of the map slice by the specified second keyk2.Uses the constant number of ordinary map operations (
get).- Specified by:
entrySetByKey2in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
entrySetByKey2in classAbstractDoubleKeyMap<Key1,Key2,Value>- Returns:
- a set view of the map slice by the second key
-
keys
@NotNull public Map<Key1,Set<Key2>> keys()
Description copied from interface:DoubleKeyMapReturns all the keys of this map in a formkey1 -> {key2}.Works in a linear time of map size.
Changes in the keys map do not reflect the changes in this map.
- Specified by:
keysin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
keysin classAbstractDoubleKeyMap<Key1,Key2,Value>- Returns:
- all map keys as a map
-
keySet1
@NotNull public Set<Key2> keySet1(@NotNull Key1 k1)
Description copied from interface:DoubleKeyMapReturns the key set of the map slice by the specified first keyk1.Uses the constant number of ordinary map operations (
get).- Specified by:
keySet1in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
keySet1in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first key- Returns:
- key set of the map slice by the first key
-
keySet2
@NotNull public Set<Key1> keySet2(@NotNull Key2 k2)
Description copied from interface:DoubleKeyMapReturns the key set of the map slice by the specified second keyk2.Uses the constant number of ordinary map operations (
get).- Specified by:
keySet2in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
keySet2in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k2- second key- Returns:
- key set of the map slice by the second key
-
values
@NotNull public Collection<Value> values()
Description copied from interface:DoubleKeyMapReturns a collection of values of this map. Result map can be empty, but nevernull.Works in a linear time of map size and uses linear memory.
Changes in the values collection do not reflect the changes in this map.
- Specified by:
valuesin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
valuesin classAbstractDoubleKeyMap<Key1,Key2,Value>- Returns:
- all map values
-
valuesByKey1
@NotNull public Collection<Value> valuesByKey1(@NotNull Key1 k1)
Description copied from interface:DoubleKeyMapReturns the values collection of the map slice by the specified first keyk1. Result map can be empty, but nevernull.Uses the constant number of ordinary map operations (
get).- Specified by:
valuesByKey1in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
valuesByKey1in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first key- Returns:
- values collection of the map slice by the first key
-
valuesByKey2
@NotNull public Collection<Value> valuesByKey2(@NotNull Key2 k2)
Description copied from interface:DoubleKeyMapReturns the values collection of the map slice by the specified second keyk2. Result map can be empty, but nevernull.Uses the constant number of ordinary map operations (
get).- Specified by:
valuesByKey2in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
valuesByKey2in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k2- second key- Returns:
- values collection of the map slice by the second key
-
remove
@Nullable public Value remove(@NotNull Key1 k1, @NotNull Key2 k2)
Description copied from interface:DoubleKeyMapRemoves the value from the map corresponding to the keys pair(k1, k2)(if present).Uses the constant number of ordinary map operations (
get,remove).- Specified by:
removein interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
removein classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first keyk2- second key- Returns:
- the previous value for the
(k1, k2)pair, ornullif it is not present
-
removeAllByKey1
@Nullable public Map<Key2,Value> removeAllByKey1(@NotNull Key1 k1)
Description copied from interface:DoubleKeyMapRemoves all values from the map corresponding to the first keyk1(if present).Works in a linear time of the size of the returned map.
- Specified by:
removeAllByKey1in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
removeAllByKey1in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k1- first key- Returns:
- the map slice by the first key
k1present just before the removal (can benull).
-
removeAllByKey2
@Nullable public Map<Key1,Value> removeAllByKey2(@NotNull Key2 k2)
Description copied from interface:DoubleKeyMapRemoves all values from the map corresponding to the second keyk2(if present).Works in a linear time of the size of the returned map.
- Specified by:
removeAllByKey2in interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
removeAllByKey2in classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
k2- second key- Returns:
- the map slice by the second key
k2present just before the removal (can benull).
-
removeAll
public void removeAll(@NotNull Collection<Key1> keys1, @NotNull Collection<Key2> keys2)Description copied from interface:DoubleKeyMapRemoves the whole sector covered by the key setskeys1andkey2). More precisely, this method removes all entries(k1, k2, v), for whichkeys1.contains(k1) && keys2.contains(k2).Time complexity is
O(n1) * O(n2), wheren1andn2are the sizes of the input collections.- Specified by:
removeAllin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
removeAllin classAbstractDoubleKeyMap<Key1,Key2,Value>- Parameters:
keys1- the first keys collectionkeys2- the second keys collection
-
clear
public void clear()
Description copied from interface:DoubleKeyMapClears the map. As a result of this call, the map size would be0.Works in a linear time of the map size.
- Specified by:
clearin interfaceDoubleKeyMap<Key1,Key2,Value>- Overrides:
clearin classAbstractDoubleKeyMap<Key1,Key2,Value>
-
-