/** * Construct a new {@code ModelMap} containing the supplied attribute * under the supplied name. * @see #addAttribute(String, Object) */ public ConcurrentModel(String attributeName, Object attributeValue) { addAttribute(attributeName, attributeValue); }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}, * with existing objects of the same name taking precedence (i.e. not getting * replaced). */ public ConcurrentModel mergeAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { attributes.forEach((key, value) -> { if (!containsKey(key)) { put(key, value); } }); } return this; }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}. * @see #addAttribute(String, Object) */ public ConcurrentModel addAllAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { putAll(attributes); } return this; }
/** * Add the supplied attribute under the supplied name. * @param attributeName the name of the model attribute (never {@code null}) * @param attributeValue the model attribute value (ignored if {@code null}, * just removing an existing entry if any) */ public ConcurrentModel addAttribute(String attributeName, @Nullable Object attributeValue) { Assert.notNull(attributeName, "Model attribute name must not be null"); put(attributeName, attributeValue); return this; }
returnValue = new ConcurrentModel().addAttribute("name", "Joe").addAttribute("ignore", null); testHandle("/account", returnType, returnValue, "account: {id=123, name=Joe}", resolver);
/** * Does this model contain an attribute of the given name? * @param attributeName the name of the model attribute (never {@code null}) * @return whether this model contains a corresponding attribute */ public boolean containsAttribute(String attributeName) { return containsKey(attributeName); }
@Override public Object put(String key, Object value) { if (value != null) { return super.put(key, value); } else { return remove(key); } }
@Override public BindingResult<Model> bind(ArgumentConversionContext<Model> context, HttpRequest<?> source) { final Optional<Model> attribute = source.getAttribute(ATTRIBUTE, Model.class); if (!attribute.isPresent()) { final ConcurrentModel concurrentModel = new ConcurrentModel(); source.setAttribute(ATTRIBUTE, concurrentModel); return () -> Optional.of(concurrentModel); } return () -> attribute; }
@Override @Nullable public Object getAttribute(String attributeName) { return get(attributeName); }
@Override public void putAll(Map<? extends String, ?> map) { for (Map.Entry<? extends String, ?> entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } }
/** * Does this model contain an attribute of the given name? * @param attributeName the name of the model attribute (never {@code null}) * @return whether this model contains a corresponding attribute */ public boolean containsAttribute(String attributeName) { return containsKey(attributeName); }
@Override public Object put(String key, Object value) { if (value != null) { return super.put(key, value); } else { return remove(key); } }
/** * Construct a new {@code ModelMap} containing the supplied attribute. * Uses attribute name generation to generate the key for the supplied model * object. * @see #addAttribute(Object) */ public ConcurrentModel(Object attributeValue) { addAttribute(attributeValue); }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}, * with existing objects of the same name taking precedence (i.e. not getting * replaced). */ public ConcurrentModel mergeAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { attributes.forEach((key, value) -> { if (!containsKey(key)) { put(key, value); } }); } return this; }
@Override public Object put(String key, Object value) { removeBindingResultIfNecessary(key, value); return super.put(key, value); }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}. * @see #addAttribute(String, Object) */ public ConcurrentModel addAllAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { putAll(attributes); } return this; }
/** * Does this model contain an attribute of the given name? * @param attributeName the name of the model attribute (never {@code null}) * @return whether this model contains a corresponding attribute */ public boolean containsAttribute(String attributeName) { return containsKey(attributeName); }
@Override public Object put(String key, Object value) { if (value != null) { return super.put(key, value); } else { return remove(key); } }
/** * Construct a new {@code ModelMap} containing the supplied attribute. * Uses attribute name generation to generate the key for the supplied model * object. * @see #addAttribute(Object) */ public ConcurrentModel(Object attributeValue) { addAttribute(attributeValue); }
/** * Copy all attributes in the supplied {@code Map} into this {@code Map}, * with existing objects of the same name taking precedence (i.e. not getting * replaced). */ public ConcurrentModel mergeAttributes(@Nullable Map<String, ?> attributes) { if (attributes != null) { attributes.forEach((key, value) -> { if (!containsKey(key)) { put(key, value); } }); } return this; }