public final class ContextResourceMap extends Object implements Serializable
Context
resources by key.Constructor and Description |
---|
ContextResourceMap(String scopeName,
boolean threadSafe)
Construct a ContextResourceMap with default initial capacity
|
ContextResourceMap(String scopeName,
boolean threadSafe,
int initialCapacity)
Construct a ContextResourceMap
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all resource bindings
|
<T> T |
get(String key,
Class<T> type)
Get a value of given
type identified by given key . |
<T> T |
put(String key,
T value)
Bind the given resource key with the specified value
|
<T> T |
putIfAbsent(String key,
T value)
Bind the given resource key with the specified value, if not already bound
|
boolean |
remove(String key)
Removes the resource instance bound to given key
|
public ContextResourceMap(String scopeName, boolean threadSafe)
scopeName
- Scope namethreadSafe
- true
to build a thread-safe resource mappublic ContextResourceMap(String scopeName, boolean threadSafe, int initialCapacity)
scopeName
- Scope namethreadSafe
- true
to build a thread-safe resource mapinitialCapacity
- Initial capacitypublic <T> T get(String key, Class<T> type) throws TypeMismatchException
type
identified by given key
.T
- Resource typekey
- Resource keytype
- Resource typenull
if not foundTypeMismatchException
- Expected and actual resource type mismatchpublic <T> T put(String key, T value)
T
- Resource typekey
- Resource key (not null)value
- Resource instance. If null
, the mapping will be removedpublic <T> T putIfAbsent(String key, T value)
T
- Resource typekey
- Resource key (not null)value
- Resource instancenull
if no value was bound and the new instance it's been mapped to the
keypublic boolean remove(String key)
key
- Resource key (not null)true
if found and removedpublic void clear()
Copyright © 2019 The Holon Platform. All rights reserved.