K
- Type of the key of the Map entriesV
- Type of the value of the Map entriespublic class PutIfAbsentMap<K,V> extends Object implements Map<K,V>
Please note that only these methods are synchronized: get/put/putAll/remove/clear.
注意只有这几个方法是同步的:get/put/putAll/remove/clear。
Modifier and Type | Field and Description |
---|---|
protected Map<K,V> |
map |
protected Object |
structureLock |
protected MapValueFactory<K,V> |
valueFactory |
Constructor and Description |
---|
PutIfAbsentMap(Class<? extends Map> mapClazz,
Class<? extends V> valueClazz)
Constructor.
|
PutIfAbsentMap(Class<? extends Map> mapClazz,
Class<? extends V> valueClazz,
Object valueParam)
Constructor.
|
PutIfAbsentMap(Class<? extends Map> mapClazz,
MapValueFactory<K,V> valueFactory)
Constructor.
|
PutIfAbsentMap(Class<? extends V> valueClazz)
Constructor.
|
PutIfAbsentMap(Class<? extends V> valueClazz,
Object valueParam)
Constructor.
|
PutIfAbsentMap(Map<K,V> originalMap,
Class<? extends V> valueClazz)
Constructs an instance with specified Map instance and value Class.
给定Map实例以及value的类,把一个普通的Map实例封装成“每次get的时候,如果没有,就自动put”。 |
PutIfAbsentMap(Map<K,V> originalMap,
Class<? extends V> valueClazz,
Object valueParam)
Constructs an instance with specified Map instance and value Class.
给定Map实例以及value的类,把一个普通的Map实例封装成“每次get的时候,如果没有,就自动put”。 |
PutIfAbsentMap(Map<K,V> originalMap,
MapValueFactory<K,V> valueFactory)
Constructor.
|
PutIfAbsentMap(MapValueFactory<K,V> valueFactory)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object obj) |
boolean |
containsValue(Object obj) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key)
Get the value object corresponding to the key object specified,
if such entry does not exist in the Map, then create one and put
into the Map and return the value object in the newly created entry.
取得key所对应的value,如果目前在Map里没有,则在Map里新建一个并返回新建 的这个value对象。 |
Map<K,V> |
getMap()
Get the encapsulated Map instance.
获得最初被封装的那个Map。 |
protected static Map |
instantiateMap(Class<? extends Map> mapClazz) |
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> anotherMap) |
V |
remove(Object obj) |
int |
size() |
String |
toString() |
Collection<V> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
protected MapValueFactory<K,V> valueFactory
protected Object structureLock
public PutIfAbsentMap(Map<K,V> originalMap, MapValueFactory<K,V> valueFactory)
originalMap
- The map to be encapsulated.valueFactory
- The factory for creating values to be put into this map.public PutIfAbsentMap(Map<K,V> originalMap, Class<? extends V> valueClazz)
originalMap
- The Map instance that will be encapsulated.valueClazz
- Class of the value of the Map entry.RuntimeException
- If no non-argument constructor can be found in valueClazz.public PutIfAbsentMap(Map<K,V> originalMap, Class<? extends V> valueClazz, Object valueParam)
originalMap
- The Map instance that will be encapsulated.valueClazz
- Class of the value of the Map entry.valueParam
- Parameter to be passed in to the constructor of valueClazz.RuntimeException
- if no correct constructor in valueClazz can be found.public PutIfAbsentMap(Class<? extends Map> mapClazz, MapValueFactory<K,V> valueFactory)
mapClazz
- The class type of the encapsulated class.valueFactory
- The factory of values to be put into this map.RuntimeException
- if cannot instantiate a new map instance.public PutIfAbsentMap(Class<? extends Map> mapClazz, Class<? extends V> valueClazz)
mapClazz
- The class type of the encapsulated class.valueClazz
- The class type of the value class.RuntimeException
- if cannot instantiate a new map instance.RuntimeException
- if no non-argument constructor can be found in valueClazzpublic PutIfAbsentMap(Class<? extends Map> mapClazz, Class<? extends V> valueClazz, Object valueParam)
mapClazz
- The class type of the encapsulated class.valueClazz
- The class type of the value class.valueParam
- Parameter that will be passed in to the constructor of valueClazzRuntimeException
- if cannot instantiate a new map instance.RuntimeException
- if no non-argument constructor can be found in valueClazzpublic PutIfAbsentMap(MapValueFactory<K,V> valueFactory)
valueFactory
- The factory of map values.public PutIfAbsentMap(Class<? extends V> valueClazz) throws NoSuchMethodException
valueClazz
- Type of the value classesNoSuchMethodException
- if valueClazz does not have a non-argument constructor.public PutIfAbsentMap(Class<? extends V> valueClazz, Object valueParam)
valueClazz
- Type of the value classesvalueParam
- Parameter that will be passed in to the constructor of valueClazzNoSuchMethodException
- if valueClazz does not have a non-argument constructor.public Map<K,V> getMap()
public V get(Object key)
public boolean containsKey(Object obj)
containsKey
in interface Map<K,V>
public boolean containsValue(Object obj)
containsValue
in interface Map<K,V>
Copyright © 2014. All Rights Reserved.