nl.vpro.domain.api.AbstractMultipleResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-domain Show documentation
Show all versions of api-domain Show documentation
Contains the objects used by the Frontend API, like forms and result objects
package nl.vpro.domain.api;
import java.util.AbstractList;
import java.util.List;
import java.util.function.BiFunction;
import javax.xml.bind.annotation.XmlTransient;
import nl.vpro.domain.constraint.DisplayablePredicate;
import nl.vpro.domain.constraint.PredicateTestResult;
/**
* @author Michiel Meeuwissen
* @since 4.7
*/
public abstract class AbstractMultipleResult extends Result> {
@XmlTransient
protected final BiFunction> producer;
public AbstractMultipleResult(BiFunction> producer) {
this.producer = producer;
this.offset = null;
}
public AbstractMultipleResult(BiFunction> producer, List ids, List objects) {
this(producer, ids, objects, null);
}
public AbstractMultipleResult(BiFunction> producer, List ids, List objects, DisplayablePredicate predicate) {
this(producer);
this.items = adapt(ids, objects, predicate);
this.total = (long) objects.size();
this.totalQualifier = TotalQualifier.EQUAL_TO;
this.offset = null;
this.max = null;
}
private List extends MultipleEntry> adapt(final List ids, final List extends M> list, DisplayablePredicate predicate) {
return new AbstractList>() {
@Override
public MultipleEntry get(int index) {
MultipleEntry entry = producer.apply(ids.get(index), list.get(index));
if (predicate != null) {
PredicateTestResult result = predicate.testWithReason(entry.getResult());
if (! result.applies()) {
entry.setError("Does not match profile " + predicate.toString() + ": " + ids.get(index));
entry.setReason(result);
entry.setResult(null); // ?
}
}
return entry;
}
@Override
public int size() {
return list.size();
}
};
}
public Result toResult() {
return stream().map(MultipleEntry::getResult).collect(Result.collector());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy