com.kenshoo.pl.entity.ChangeResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-layer Show documentation
Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
package com.kenshoo.pl.entity;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Function;
import static java.util.stream.Collectors.toMap;
import static org.jooq.lambda.Seq.seq;
public class ChangeResult, ID extends Identifier, C extends ChangeEntityCommand> implements Iterable> {
private final Collection> changeResults;
private final Map, EntityChangeResult> resultsAsMap;
private final PersistentLayerStats stats;
public ChangeResult(Iterable extends EntityChangeResult> changeResults, PersistentLayerStats stats) {
this.changeResults = ImmutableList.copyOf(changeResults);
resultsAsMap = seq(this.changeResults).collect(toMap(EntityChangeResult::getCommand, Function.identity()));
this.stats = stats;
}
public boolean hasErrors() {
return changeResults.stream().anyMatch(changeResult -> !changeResult.getErrors().isEmpty());
}
public boolean hasErrors(C command) {
return !getErrors(command).isEmpty();
}
public Collection getErrors(C command) {
return resultsAsMap.get(command).getErrors();
}
@Override
public Iterator> iterator() {
return changeResults.iterator();
}
public Collection> getChangeResults() {
return changeResults;
}
public PersistentLayerStats getStats() {
return stats;
}
}