org.springframework.ui

Class ConcurrentModel

  • java.lang.Object
    • java.util.AbstractMap<K,V>
      • java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object>
        • org.springframework.ui.ConcurrentModel
  • All Implemented Interfaces:
    java.io.Serializable, java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object>, java.util.Map<java.lang.String,java.lang.Object>, Model
    Direct Known Subclasses:
    BindingAwareConcurrentModel


    public class ConcurrentModel
    extends java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object>
    implements Model
    Implementation of the 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.

    Since:
    5.0
    Author:
    Rossen Stoyanchev
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap

        java.util.concurrent.ConcurrentHashMap.KeySetView<K,V>
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K,V>
    • Constructor Summary

      Constructors 
      Constructor and Description
      ConcurrentModel()
      Construct a new, empty ConcurrentModel.
      ConcurrentModel(java.lang.Object attributeValue)
      Construct a new ModelMap containing the supplied attribute.
      ConcurrentModel(java.lang.String attributeName, java.lang.Object attributeValue)
      Construct a new ModelMap containing the supplied attribute under the supplied name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      ConcurrentModel addAllAttributes(java.util.Collection<?> attributeValues)
      Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.
      ConcurrentModel addAllAttributes(java.util.Map<java.lang.String,?> attributes)
      Copy all attributes in the supplied Map into this Map.
      ConcurrentModel addAttribute(java.lang.Object attributeValue)
      Add the supplied attribute to this Map using a generated name.
      ConcurrentModel addAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
      Add the supplied attribute under the supplied name.
      java.util.Map<java.lang.String,java.lang.Object> asMap()
      Return the current set of model attributes as a Map.
      boolean containsAttribute(java.lang.String attributeName)
      Does this model contain an attribute of the given name?
      ConcurrentModel mergeAttributes(java.util.Map<java.lang.String,?> attributes)
      Copy all attributes in the supplied Map into this Map, with existing objects of the same name taking precedence (i.e.
      java.lang.Object put(java.lang.String key, java.lang.Object value) 
      void putAll(java.util.Map<? extends java.lang.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
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ConcurrentModel

        public ConcurrentModel()
        Construct a new, empty ConcurrentModel.
      • ConcurrentModel

        public ConcurrentModel(java.lang.String attributeName,
                               java.lang.Object attributeValue)
        Construct a new ModelMap containing the supplied attribute under the supplied name.
        See Also:
        addAttribute(String, Object)
      • ConcurrentModel

        public ConcurrentModel(java.lang.Object attributeValue)
        Construct a new ModelMap containing the supplied attribute. Uses attribute name generation to generate the key for the supplied model object.
        See Also:
        addAttribute(Object)
    • Method Detail

      • put

        public java.lang.Object put(java.lang.String key,
                                    java.lang.Object value)
        Specified by:
        put in interface java.util.Map<java.lang.String,java.lang.Object>
        Overrides:
        put in class java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object>
      • putAll

        public void putAll(java.util.Map<? extends java.lang.String,?> map)
        Specified by:
        putAll in interface java.util.Map<java.lang.String,java.lang.Object>
        Overrides:
        putAll in class java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Object>
      • addAttribute

        public ConcurrentModel addAttribute(java.lang.String attributeName,
                                            @Nullable
                                            java.lang.Object attributeValue)
        Add the supplied attribute under the supplied name.
        Specified by:
        addAttribute in interface Model
        Parameters:
        attributeName - the name of the model attribute (never null)
        attributeValue - the model attribute value (ignored if null, just removing an existing entry if any)
      • addAttribute

        public ConcurrentModel addAttribute(java.lang.Object attributeValue)
        Add the supplied attribute to this 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.

        Specified by:
        addAttribute in interface Model
        Parameters:
        attributeValue - the model attribute value (never null)
      • mergeAttributes

        public ConcurrentModel mergeAttributes(@Nullable
                                               java.util.Map<java.lang.String,?> attributes)
        Copy all attributes in the supplied Map into this Map, with existing objects of the same name taking precedence (i.e. not getting replaced).
        Specified by:
        mergeAttributes in interface Model
      • containsAttribute

        public boolean containsAttribute(java.lang.String attributeName)
        Does this model contain an attribute of the given name?
        Specified by:
        containsAttribute in interface Model
        Parameters:
        attributeName - the name of the model attribute (never null)
        Returns:
        whether this model contains a corresponding attribute
      • asMap

        public java.util.Map<java.lang.String,java.lang.Object> asMap()
        Description copied from interface: Model
        Return the current set of model attributes as a Map.
        Specified by:
        asMap in interface Model