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
AMapContextprovides 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 voidclear()booleancontainsKey(Object o)booleancontainsValue(Object o)Set<Map.Entry<String,Object>>entrySet()Objectget(Object o)protected <E> EgetTypedValue(String key, Class<E> type)Performs agetoperation but additionally ensures that the value returned is of the specifiedtype.booleanisEmpty()Set<String>keySet()protected voidnullSafePut(String key, Object value)Places a value in this context map under the given key only if the givenvalueargument is not null.Objectput(String s, Object o)voidputAll(Map<? extends String,?> map)Objectremove(Object o)intsize()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
-
-
-
-
Method Detail
-
getTypedValue
protected <E> E getTypedValue(String key, Class<E> type)
Performs agetoperation but additionally ensures that the value returned is of the specifiedtype. If there is no value,nullis 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
nullif 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 givenvalueargument 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:
containsKeyin interfaceMap<String,Object>
-
containsValue
public boolean containsValue(Object o)
- Specified by:
containsValuein interfaceMap<String,Object>
-
-