You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/05/03 13:50:53 UTC
(commons-beanutils) branch master updated: Refactor for duplication
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push:
new 6a035eae Refactor for duplication
6a035eae is described below
commit 6a035eaeeef071fd2907d50499825b68279f445b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 3 09:50:48 2024 -0400
Refactor for duplication
Create exception message on demand
---
.../java/org/apache/commons/beanutils2/BasicDynaBean.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java b/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
index d467a65b..4dc6c3d1 100644
--- a/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java
@@ -96,7 +96,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
public boolean contains(final String name, final String key) {
final Object value = values.get(name);
- Objects.requireNonNull(value, "No mapped value for '" + name + "(" + key + ")'");
+ requireMappedValue(name, key, value);
if (value instanceof Map) {
return ((Map<?, ?>) value).containsKey(key);
}
@@ -207,7 +207,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
public Object get(final String name, final String key) {
final Object value = values.get(name);
- Objects.requireNonNull(value, "No mapped value for '" + name + "(" + key + ")'");
+ requireMappedValue(name, key, value);
if (value instanceof Map) {
return ((Map<?, ?>) value).get(key);
}
@@ -310,7 +310,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
public void remove(final String name, final String key) {
final Object value = values.get(name);
- Objects.requireNonNull(value, "No mapped value for '" + name + "(" + key + ")'");
+ requireMappedValue(name, key, value);
if (!(value instanceof Map)) {
throw new IllegalArgumentException
("Non-mapped property for '" + name + "(" + key + ")'");
@@ -319,6 +319,10 @@ public class BasicDynaBean implements DynaBean, Serializable {
}
+ private void requireMappedValue(final String name, final String key, final Object value) {
+ Objects.requireNonNull(value, () -> "No mapped value for '" + name + "(" + key + ")'");
+ }
+
/**
* Sets the value of an indexed property with the specified name.
*
@@ -408,7 +412,7 @@ public class BasicDynaBean implements DynaBean, Serializable {
public void set(final String name, final String key, final Object value) {
final Object prop = values.get(name);
- Objects.requireNonNull(prop, "No mapped value for '" + name + "(" + key + ")'");
+ requireMappedValue(name, key, prop);
if (!(prop instanceof Map)) {
throw new IllegalArgumentException
("Non-mapped property for '" + name + "(" + key + ")'");