Use forEach()
This commit is contained in:
parent
78ce2d79f2
commit
9f0f3c838b
|
@ -948,19 +948,13 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
|
|||
* @throws NullPointerException if field name is {@code null}
|
||||
* @since 3.5
|
||||
*/
|
||||
public DiffBuilder<T> append(final String fieldName,
|
||||
final DiffResult<T> diffResult) {
|
||||
public DiffBuilder<T> append(final String fieldName, final DiffResult<T> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -197,13 +197,12 @@ public class DiffResult<T> implements Iterable<Diff<?>> {
|
|||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -98,9 +98,9 @@ import org.apache.commons.lang3.Validate;
|
|||
public class MultiBackgroundInitializer
|
||||
extends
|
||||
BackgroundInitializer<MultiBackgroundInitializer.MultiBackgroundInitializerResults> {
|
||||
|
||||
/** A map with the child initializers. */
|
||||
private final Map<String, BackgroundInitializer<?>> childInitializers =
|
||||
new HashMap<>();
|
||||
private final Map<String, BackgroundInitializer<?>> 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<String, BackgroundInitializer<?>> 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<String, Object> results = new HashMap<>();
|
||||
final Map<String, ConcurrentException> excepts = new HashMap<>();
|
||||
for (final Map.Entry<String, BackgroundInitializer<?>> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue