Package org.springframework.ui
Class ConcurrentModel
- java.lang.Object
- java.util.AbstractMap<K,V>
- java.util.concurrent.ConcurrentHashMap<String,Object>
- org.springframework.ui.ConcurrentModel
- All Implemented Interfaces:
Serializable,ConcurrentMap<String,Object>,Map<String,Object>,Model
- Direct Known Subclasses:
BindingAwareConcurrentModel
public class ConcurrentModel extends ConcurrentHashMap<String,Object> implements Model
Implementation of theModelinterface based on aConcurrentHashMapfor use in concurrent scenarios.Exposed to handler methods by Spring WebFlux, typically via a declaration of the
Modelinterface. There is typically no need to create it within user code. If necessary a handler method can return a regularjava.util.Map, likely ajava.util.ConcurrentMap, for a pre-determined model.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
- See Also:
- Serialized Form
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap
ConcurrentHashMap.KeySetView<K extends Object,V extends Object>
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
Constructor Summary
Constructors Constructor Description ConcurrentModel()Construct a new, emptyConcurrentModel.ConcurrentModel(Object attributeValue)Construct a newModelMapcontaining the supplied attribute.ConcurrentModel(String attributeName, Object attributeValue)Construct a newModelMapcontaining the supplied attribute under the supplied name.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConcurrentModeladdAllAttributes(Collection<?> attributeValues)Copy all attributes in the suppliedCollectioninto thisMap, using attribute name generation for each element.ConcurrentModeladdAllAttributes(Map<String,?> attributes)Copy all attributes in the suppliedMapinto thisMap.ConcurrentModeladdAttribute(Object attributeValue)Add the supplied attribute to thisMapusing agenerated name.ConcurrentModeladdAttribute(String attributeName, Object attributeValue)Add the supplied attribute under the supplied name.Map<String,Object>asMap()Return the current set of model attributes as a Map.booleancontainsAttribute(String attributeName)Does this model contain an attribute of the given name?ObjectgetAttribute(String attributeName)Return the attribute value for the given name, if any.ConcurrentModelmergeAttributes(Map<String,?> attributes)Copy all attributes in the suppliedMapinto thisMap, with existing objects of the same name taking precedence (i.e.Objectput(String key, Object value)voidputAll(Map<? extends String,?> map)Methods inherited from class java.util.concurrent.ConcurrentHashMap
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, get, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, values
Methods inherited from class java.util.AbstractMap
clone
Constructor Detail
ConcurrentModel
public ConcurrentModel()
Construct a new, emptyConcurrentModel.
ConcurrentModel
public ConcurrentModel(String attributeName, Object attributeValue)
Construct a newModelMapcontaining the supplied attribute under the supplied name.- See Also:
addAttribute(String, Object)
ConcurrentModel
public ConcurrentModel(Object attributeValue)
Construct a newModelMapcontaining the supplied attribute. Uses attribute name generation to generate the key for the supplied model object.- See Also:
addAttribute(Object)
Method Detail
addAttribute
public ConcurrentModel addAttribute(String attributeName, @Nullable Object attributeValue)
Add the supplied attribute under the supplied name.- Specified by:
addAttributein interfaceModel- Parameters:
attributeName- the name of the model attribute (nevernull)attributeValue- the model attribute value (ignored ifnull, just removing an existing entry if any)
addAttribute
public ConcurrentModel addAttribute(Object attributeValue)
Add the supplied attribute to thisMapusing agenerated name.Note: Empty
Collectionsare not added to the model when using this method because we cannot correctly determine the true convention name. View code should check fornullrather than for empty collections as is already done by JSTL tags.- Specified by:
addAttributein interfaceModel- Parameters:
attributeValue- the model attribute value (nevernull)
addAllAttributes
public ConcurrentModel addAllAttributes(@Nullable Collection<?> attributeValues)
Copy all attributes in the suppliedCollectioninto thisMap, using attribute name generation for each element.- Specified by:
addAllAttributesin interfaceModel- See Also:
addAttribute(Object)
addAllAttributes
public ConcurrentModel addAllAttributes(@Nullable Map<String,?> attributes)
Copy all attributes in the suppliedMapinto thisMap.- Specified by:
addAllAttributesin interfaceModel- See Also:
addAttribute(String, Object)
mergeAttributes
public ConcurrentModel mergeAttributes(@Nullable Map<String,?> attributes)
Copy all attributes in the suppliedMapinto thisMap, with existing objects of the same name taking precedence (i.e. not getting replaced).- Specified by:
mergeAttributesin interfaceModel
containsAttribute
public boolean containsAttribute(String attributeName)
Does this model contain an attribute of the given name?- Specified by:
containsAttributein interfaceModel- Parameters:
attributeName- the name of the model attribute (nevernull)- Returns:
- whether this model contains a corresponding attribute
getAttribute
@Nullable public Object getAttribute(String attributeName)
Description copied from interface:ModelReturn the attribute value for the given name, if any.- Specified by:
getAttributein interfaceModel- Parameters:
attributeName- the name of the model attribute (nevernull)- Returns:
- the corresponding attribute value, or
nullif none