Skip to content

Commit 2c5ef01

Browse files
committed
Use forEach()
1 parent 296dcfe commit 2c5ef01

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ public void putAll(final Map<? extends K, ? extends Object> map) {
264264
if (isReadOnly()) {
265265
throw new UnsupportedOperationException("Map is read only");
266266
}
267-
for (final Map.Entry<? extends K, ?> e : map.entrySet()) {
268-
put(e.getKey(), e.getValue());
269-
}
267+
map.forEach(this::put);
270268
}
271269

272270
/**

src/main/java/org/apache/commons/beanutils2/BeanMap.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ public Object clone() throws CloneNotSupportedException {
164164
// copy only properties that are readable and writable. If its
165165
// not readable, we can't get the value from the old map. If
166166
// its not writable, we can't write a value into the new map.
167-
for (final String key : readMethods.keySet()) {
167+
readMethods.keySet().forEach(key -> {
168168
if (getWriteMethod(key) != null) {
169169
newMap.put(key, get(key));
170170
}
171-
}
171+
});
172172
} catch (final Exception exception) {
173173
final CloneNotSupportedException cnse = new CloneNotSupportedException(
174174
"Unable to copy bean values to cloned bean map: " + exception);
@@ -186,11 +186,11 @@ public Object clone() throws CloneNotSupportedException {
186186
* @param map the BeanMap whose properties to put
187187
*/
188188
public void putAllWriteable(final BeanMap map) {
189-
for (final String key : map.readMethods.keySet()) {
189+
map.readMethods.keySet().forEach(key -> {
190190
if (getWriteMethod(key) != null) {
191191
this.put(key, map.get(key));
192192
}
193-
}
193+
});
194194
}
195195

196196
/**
@@ -368,9 +368,7 @@ public int size() {
368368
@Override
369369
public Collection<Object> values() {
370370
final ArrayList<Object> answer = new ArrayList<>(readMethods.size());
371-
for (final Iterator<Object> iter = valueIterator(); iter.hasNext();) {
372-
answer.add(iter.next());
373-
}
371+
valueIterator().forEachRemaining(answer::add);
374372
return Collections.unmodifiableList(answer);
375373
}
376374

src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.lang.reflect.Array;
2323
import java.lang.reflect.InvocationTargetException;
2424
import java.lang.reflect.Method;
25-
import java.util.ArrayList;
2625
import java.util.Collection;
2726
import java.util.HashMap;
2827
import java.util.List;
@@ -243,9 +242,9 @@ public void copyProperties(final Object dest, final Object orig)
243242
// Map properties are always of type <String, Object>
244243
Map<String, Object> propMap = (Map<String, Object>) orig;
245244
for (final Map.Entry<String, Object> entry : propMap.entrySet()) {
246-
final String name = entry.getKey();
247-
if (getPropertyUtils().isWriteable(dest, name)) {
248-
copyProperty(dest, name, entry.getValue());
245+
final String k = entry.getKey();
246+
if (getPropertyUtils().isWriteable(dest, k)) {
247+
copyProperty(dest, k, entry.getValue());
249248
}
250249
}
251250
} else /* if (orig is a standard JavaBean) */ {
@@ -514,16 +513,7 @@ public String[] getArrayProperty(final Object bean, final String name)
514513
return null;
515514
}
516515
if (value instanceof Collection) {
517-
final ArrayList<String> values = new ArrayList<>();
518-
for (final Object item : (Collection<?>) value) {
519-
if (item == null) {
520-
values.add(null);
521-
} else {
522-
// convert to string using convert utils
523-
values.add(getConvertUtils().convert(item));
524-
}
525-
}
526-
return values.toArray(new String[values.size()]);
516+
return ((Collection<?>) value).stream().map(item -> item != null ? getConvertUtils().convert(item) : null).toArray(String[]::new);
527517
}
528518
if (!value.getClass().isArray()) {
529519
final String[] results = new String[1];

src/main/java/org/apache/commons/beanutils2/LazyDynaList.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ public boolean addAll(final Collection<?> collection) {
292292

293293
ensureCapacity(size() + collection.size());
294294

295-
for (final Object e : collection) {
296-
add(e);
297-
}
295+
collection.forEach(this::add);
298296

299297
return true;
300298
}

src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public Set<String> getSuppressedProperties() {
8484
*/
8585
@Override
8686
public void introspect(final IntrospectionContext icontext) throws IntrospectionException {
87-
for (final String property : getSuppressedProperties()) {
88-
icontext.removePropertyDescriptor(property);
89-
}
87+
getSuppressedProperties().forEach(icontext::removePropertyDescriptor);
9088
}
9189
}

0 commit comments

Comments
 (0)