Model interface exposes getAttribute method (next to add/contains)

Fixes gh-22145
This commit is contained in:
Juergen Hoeller
2019-01-28 22:50:29 +01:00
parent 80385ced4c
commit 5aed117b68
3 changed files with 29 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -161,6 +161,12 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement
return containsKey(attributeName);
}
@Override
@Nullable
public Object getAttribute(String attributeName) {
return get(attributeName);
}
@Override
public Map<String, Object> asMap() {
return this;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,6 +76,15 @@ public interface Model {
*/
boolean containsAttribute(String attributeName);
/**
* Return the attribute value for the given name, if any.
* @param attributeName the name of the model attribute (never {@code null})
* @return the corresponding attribute value, or {@code null} if none
* @since 5.2
*/
@Nullable
Object getAttribute(String attributeName);
/**
* Return the current set of model attributes as a Map.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -144,4 +144,15 @@ public class ModelMap extends LinkedHashMap<String, Object> {
return containsKey(attributeName);
}
/**
* Return the attribute value for the given name, if any.
* @param attributeName the name of the model attribute (never {@code null})
* @return the corresponding attribute value, or {@code null} if none
* @since 5.2
*/
@Nullable
public Object getAttribute(String attributeName) {
return get(attributeName);
}
}