All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kenshoo.pl.entity.ChangeResult Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
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> 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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy