Browse Source

Introduce putIfAbsent() in AnnotationAttributes

Issue: SPR-13060
pull/808/head
Sam Brannen 10 years ago
parent
commit
ca09b1ff20
  1. 5
      spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java
  2. 19
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java

5
spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java

@ -963,10 +963,7 @@ public class AnnotatedElementUtils { @@ -963,10 +963,7 @@ public class AnnotatedElementUtils {
String aliasedAttributeNameInTarget = AnnotationUtils.getAliasedAttributeName(
attributeMethodInTarget, null);
if (aliasedAttributeNameInTarget != null) {
Object aliasedValueInTarget = attributes.get(aliasedAttributeNameInTarget);
if (aliasedValueInTarget == null) {
attributes.put(aliasedAttributeNameInTarget, adaptedValue);
}
attributes.putIfAbsent(aliasedAttributeNameInTarget, adaptedValue);
}
}
}

19
spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java

@ -158,6 +158,25 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> { @@ -158,6 +158,25 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
return (T) value;
}
/**
* Store the supplied {@code value} in this map under the specified
* {@code key}, unless a value is already stored under the key.
* @param key the key under which to store the value
* @param value the value to store
* @return the current value stored in this map, or {@code null} if no
* value was previously stored in this map
* @see #get
* @see #put
*/
@Override
public Object putIfAbsent(String key, Object value) {
Object obj = get(key);
if (obj == null) {
obj = put(key, value);
}
return obj;
}
@Override
public String toString() {
Iterator<Map.Entry<String, Object>> entries = entrySet().iterator();

Loading…
Cancel
Save