diff --git a/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java index 183a0450a..b2dd21269 100644 --- a/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java @@ -948,19 +948,13 @@ public class DiffBuilder implements Builder> { * @throws NullPointerException if field name is {@code null} * @since 3.5 */ - public DiffBuilder append(final String fieldName, - final DiffResult diffResult) { + public DiffBuilder append(final String fieldName, final DiffResult diffResult) { validateFieldNameNotNull(fieldName); Validate.notNull(diffResult, "diffResult"); if (objectsTriviallyEqual) { return this; } - - for (final Diff diff : diffResult.getDiffs()) { - append(fieldName + "." + diff.getFieldName(), - diff.getLeft(), diff.getRight()); - } - + diffResult.getDiffs().forEach(diff -> append(fieldName + "." + diff.getFieldName(), diff.getLeft(), diff.getRight())); return this; } diff --git a/src/main/java/org/apache/commons/lang3/builder/DiffResult.java b/src/main/java/org/apache/commons/lang3/builder/DiffResult.java index df1ec7e5b..9c3f5fcf3 100644 --- a/src/main/java/org/apache/commons/lang3/builder/DiffResult.java +++ b/src/main/java/org/apache/commons/lang3/builder/DiffResult.java @@ -197,13 +197,12 @@ public class DiffResult implements Iterable> { final ToStringBuilder lhsBuilder = new ToStringBuilder(lhs, style); final ToStringBuilder rhsBuilder = new ToStringBuilder(rhs, style); - for (final Diff diff : diffList) { + diffList.forEach(diff -> { lhsBuilder.append(diff.getFieldName(), diff.getLeft()); rhsBuilder.append(diff.getFieldName(), diff.getRight()); - } + }); - return String.format("%s %s %s", lhsBuilder.build(), DIFFERS_STRING, - rhsBuilder.build()); + return String.format("%s %s %s", lhsBuilder.build(), DIFFERS_STRING, rhsBuilder.build()); } /** diff --git a/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java index 9ce572d5a..e08552099 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java @@ -98,9 +98,9 @@ import org.apache.commons.lang3.Validate; public class MultiBackgroundInitializer extends BackgroundInitializer { + /** A map with the child initializers. */ - private final Map> childInitializers = - new HashMap<>(); + private final Map> childInitializers = new HashMap<>(); /** * Creates a new instance of {@link MultiBackgroundInitializer}. @@ -156,13 +156,7 @@ public class MultiBackgroundInitializer */ @Override protected int getTaskCount() { - int result = 1; - - for (final BackgroundInitializer bi : childInitializers.values()) { - result += bi.getTaskCount(); - } - - return result; + return 1 + childInitializers.values().stream().mapToInt(BackgroundInitializer::getTaskCount).sum(); } /** @@ -180,30 +174,29 @@ public class MultiBackgroundInitializer final Map> inits; synchronized (this) { // create a snapshot to operate on - inits = new HashMap<>( - childInitializers); + inits = new HashMap<>(childInitializers); } // start the child initializers final ExecutorService exec = getActiveExecutor(); - for (final BackgroundInitializer bi : inits.values()) { + inits.values().forEach(bi -> { if (bi.getExternalExecutor() == null) { // share the executor service if necessary bi.setExternalExecutor(exec); } bi.start(); - } + }); // collect the results final Map results = new HashMap<>(); final Map excepts = new HashMap<>(); - for (final Map.Entry> e : inits.entrySet()) { + inits.entrySet().forEach(e -> { try { results.put(e.getKey(), e.getValue().get()); } catch (final ConcurrentException cex) { excepts.put(e.getKey(), cex); } - } + }); return new MultiBackgroundInitializerResults(inits, results, excepts); }