Package org.apache.shiro.util
Class MapContext
- java.lang.Object
-
- org.apache.shiro.util.MapContext
-
- All Implemented Interfaces:
Serializable
,Map<String,Object>
- Direct Known Subclasses:
DefaultSessionContext
,DefaultSubjectContext
public class MapContext extends Object implements Map<String,Object>, Serializable
AMapContext
provides a common base for context-based data storage in aMap
. Type-safe attribute retrieval is provided for subclasses with thegetTypedValue(String, Class)
method.- Since:
- 1.0
- See Also:
SubjectContext
,SessionContext
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MapContext()
MapContext(Map<String,Object> map)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object o)
boolean
containsValue(Object o)
Set<Map.Entry<String,Object>>
entrySet()
Object
get(Object o)
protected <E> E
getTypedValue(String key, Class<E> type)
Performs aget
operation but additionally ensures that the value returned is of the specifiedtype
.boolean
isEmpty()
Set<String>
keySet()
protected void
nullSafePut(String key, Object value)
Places a value in this context map under the given key only if the givenvalue
argument is not null.Object
put(String s, Object o)
void
putAll(Map<? extends String,?> map)
Object
remove(Object o)
int
size()
Collection<Object>
values()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
MapContext
public MapContext()
-
MapContext
public MapContext(Map<String,Object> map)
-
-
Method Detail
-
getTypedValue
protected <E> E getTypedValue(String key, Class<E> type)
Performs aget
operation but additionally ensures that the value returned is of the specifiedtype
. If there is no value,null
is returned.- Type Parameters:
E
- the expected type of the value- Parameters:
key
- the attribute key to look up a valuetype
- the expected type of the value- Returns:
- the typed value or
null
if the attribute does not exist.
-
nullSafePut
protected void nullSafePut(String key, Object value)
Places a value in this context map under the given key only if the givenvalue
argument is not null.- Parameters:
key
- the attribute key under which the non-null value will be storedvalue
- the non-null value to store. Ifnull
, this method does nothing and returns immediately.
-
containsKey
public boolean containsKey(Object o)
- Specified by:
containsKey
in interfaceMap<String,Object>
-
containsValue
public boolean containsValue(Object o)
- Specified by:
containsValue
in interfaceMap<String,Object>
-
-