// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.errorhandling; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; /** * @author tonytv */ public class Results { private final List data; private final List errors; public Results(List data, List errors) { this.data = ImmutableList.copyOf(data); this.errors = ImmutableList.copyOf(errors); } public boolean hasErrors() { return !errors.isEmpty(); } public List data() { return data; } public List errors() { return errors; } public static class Builder { private final List data = new ArrayList<>(); private final List errors = new ArrayList<>(); public void addData(DATA d) { data.add(d); } public void addAllData(Collection d) { data.addAll(d); } public void addError(ERROR e) { errors.add(e); } public void addAllErrors(Collection e) { errors.addAll(e); } public Results build() { return new Results<>(data, errors); } } }