public class ConcurrentModel extends ConcurrentHashMap<String,Object> implements Model
Model
interface based on a ConcurrentHashMap
for use in concurrent scenarios.
Exposed to handler methods by Spring WebFlux, typically via a declaration of the
Model
interface. There is typically no need to create it within user code.
If necessary a handler method can return a regular java.util.Map
,
likely a java.util.ConcurrentMap
, for a pre-determined model.
ConcurrentHashMap.KeySetView<K,V>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
ConcurrentModel()
Construct a new, empty
ConcurrentModel . |
ConcurrentModel(Object attributeValue)
Construct a new
ModelMap containing the supplied attribute. |
ConcurrentModel(String attributeName,
Object attributeValue)
Construct a new
ModelMap containing the supplied attribute
under the supplied name. |
Modifier and Type | Method and Description |
---|---|
ConcurrentModel |
addAllAttributes(Collection<?> attributeValues)
Copy all attributes in the supplied
Collection into this
Map , using attribute name generation for each element. |
ConcurrentModel |
addAllAttributes(Map<String,?> attributes)
Copy all attributes in the supplied
Map into this Map . |
ConcurrentModel |
addAttribute(Object attributeValue)
Add the supplied attribute to this
Map using a
generated name . |
ConcurrentModel |
addAttribute(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.
|
boolean |
containsAttribute(String attributeName)
Does this model contain an attribute of the given name?
|
ConcurrentModel |
mergeAttributes(Map<String,?> attributes)
Copy all attributes in the supplied
Map into this Map ,
with existing objects of the same name taking precedence (i.e. |
Object |
put(String key,
Object value) |
void |
putAll(Map<? extends String,?> map) |
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
clone
public ConcurrentModel()
ConcurrentModel
.public ConcurrentModel(String attributeName, Object attributeValue)
ModelMap
containing the supplied attribute
under the supplied name.addAttribute(String, Object)
public ConcurrentModel(Object attributeValue)
ModelMap
containing the supplied attribute.
Uses attribute name generation to generate the key for the supplied model
object.addAttribute(Object)
public ConcurrentModel addAttribute(String attributeName, @Nullable Object attributeValue)
addAttribute
in interface Model
attributeName
- the name of the model attribute (never null
)attributeValue
- the model attribute value (ignored if null
,
just removing an existing entry if any)public ConcurrentModel addAttribute(Object attributeValue)
Map
using a
generated name
.
Note: Empty Collections
are not added to
the model when using this method because we cannot correctly determine
the true convention name. View code should check for null
rather
than for empty collections as is already done by JSTL tags.
addAttribute
in interface Model
attributeValue
- the model attribute value (never null
)public ConcurrentModel addAllAttributes(@Nullable Collection<?> attributeValues)
Collection
into this
Map
, using attribute name generation for each element.addAllAttributes
in interface Model
addAttribute(Object)
public ConcurrentModel addAllAttributes(@Nullable Map<String,?> attributes)
Map
into this Map
.addAllAttributes
in interface Model
addAttribute(String, Object)
public ConcurrentModel mergeAttributes(@Nullable Map<String,?> attributes)
Map
into this Map
,
with existing objects of the same name taking precedence (i.e. not getting
replaced).mergeAttributes
in interface Model
public boolean containsAttribute(String attributeName)
containsAttribute
in interface Model
attributeName
- the name of the model attribute (never null
)