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 2c5ef019 Use forEach() 2c5ef019 is described below commit 2c5ef0191b13575f250d8daab765089cd8b45195 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Jul 17 11:17:20 2022 -0400 Use forEach() --- .../commons/beanutils2/BaseDynaBeanMapDecorator.java | 4 +--- .../java/org/apache/commons/beanutils2/BeanMap.java | 12 +++++------- .../org/apache/commons/beanutils2/BeanUtilsBean.java | 18 ++++-------------- .../org/apache/commons/beanutils2/LazyDynaList.java | 4 +--- .../beanutils2/SuppressPropertiesBeanIntrospector.java | 4 +--- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java b/src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java index 4d33a712..99926c8f 100644 --- a/src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java +++ b/src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java @@ -264,9 +264,7 @@ public abstract class BaseDynaBeanMapDecorator<K> implements Map<K, Object> { if (isReadOnly()) { throw new UnsupportedOperationException("Map is read only"); } - for (final Map.Entry<? extends K, ?> e : map.entrySet()) { - put(e.getKey(), e.getValue()); - } + map.forEach(this::put); } /** diff --git a/src/main/java/org/apache/commons/beanutils2/BeanMap.java b/src/main/java/org/apache/commons/beanutils2/BeanMap.java index 54f0cb71..70844df6 100644 --- a/src/main/java/org/apache/commons/beanutils2/BeanMap.java +++ b/src/main/java/org/apache/commons/beanutils2/BeanMap.java @@ -164,11 +164,11 @@ public class BeanMap extends AbstractMap<String, Object> implements Cloneable { // copy only properties that are readable and writable. If its // not readable, we can't get the value from the old map. If // its not writable, we can't write a value into the new map. - for (final String key : readMethods.keySet()) { + readMethods.keySet().forEach(key -> { if (getWriteMethod(key) != null) { newMap.put(key, get(key)); } - } + }); } catch (final Exception exception) { final CloneNotSupportedException cnse = new CloneNotSupportedException( "Unable to copy bean values to cloned bean map: " + exception); @@ -186,11 +186,11 @@ public class BeanMap extends AbstractMap<String, Object> implements Cloneable { * @param map the BeanMap whose properties to put */ public void putAllWriteable(final BeanMap map) { - for (final String key : map.readMethods.keySet()) { + map.readMethods.keySet().forEach(key -> { if (getWriteMethod(key) != null) { this.put(key, map.get(key)); } - } + }); } /** @@ -368,9 +368,7 @@ public class BeanMap extends AbstractMap<String, Object> implements Cloneable { @Override public Collection<Object> values() { final ArrayList<Object> answer = new ArrayList<>(readMethods.size()); - for (final Iterator<Object> iter = valueIterator(); iter.hasNext();) { - answer.add(iter.next()); - } + valueIterator().forEachRemaining(answer::add); return Collections.unmodifiableList(answer); } diff --git a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java index 51effe4c..0a7c683f 100644 --- a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java @@ -22,7 +22,6 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -243,9 +242,9 @@ public class BeanUtilsBean { // Map properties are always of type <String, Object> Map<String, Object> propMap = (Map<String, Object>) orig; for (final Map.Entry<String, Object> entry : propMap.entrySet()) { - final String name = entry.getKey(); - if (getPropertyUtils().isWriteable(dest, name)) { - copyProperty(dest, name, entry.getValue()); + final String k = entry.getKey(); + if (getPropertyUtils().isWriteable(dest, k)) { + copyProperty(dest, k, entry.getValue()); } } } else /* if (orig is a standard JavaBean) */ { @@ -514,16 +513,7 @@ public class BeanUtilsBean { return null; } if (value instanceof Collection) { - final ArrayList<String> values = new ArrayList<>(); - for (final Object item : (Collection<?>) value) { - if (item == null) { - values.add(null); - } else { - // convert to string using convert utils - values.add(getConvertUtils().convert(item)); - } - } - return values.toArray(new String[values.size()]); + return ((Collection<?>) value).stream().map(item -> item != null ? getConvertUtils().convert(item) : null).toArray(String[]::new); } if (!value.getClass().isArray()) { final String[] results = new String[1]; diff --git a/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java b/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java index bb0d71ed..2c443780 100644 --- a/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java +++ b/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java @@ -292,9 +292,7 @@ public class LazyDynaList extends ArrayList<Object> { ensureCapacity(size() + collection.size()); - for (final Object e : collection) { - add(e); - } + collection.forEach(this::add); return true; } diff --git a/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java b/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java index cc1aedc8..a5477904 100644 --- a/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java +++ b/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java @@ -84,8 +84,6 @@ public class SuppressPropertiesBeanIntrospector implements BeanIntrospector { */ @Override public void introspect(final IntrospectionContext icontext) throws IntrospectionException { - for (final String property : getSuppressedProperties()) { - icontext.removePropertyDescriptor(property); - } + getSuppressedProperties().forEach(icontext::removePropertyDescriptor); } }