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

com.xlrit.gears.engine.error.InputErrors Maven / Gradle / Ivy

package com.xlrit.gears.engine.error;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InputErrors {
	private static final Logger LOG = LoggerFactory.getLogger(InputErrors.class);

	private final List errors = new ArrayList<>();

	public InputErrors() {}

	public InputErrors(InputError error) {
		this.errors.add(error);
	}

	public InputErrors(List errors) {
		this.errors.addAll(errors);
	}

	public void add(InputError error) {
		errors.add(error);
	}

	public void addAll(InputErrors error) {
		errors.addAll(error.getErrors());
	}

	public long size() {
		return errors.size();
	}

	public boolean isEmpty() {
		return size() == 0;
	}

	public List getErrors() {
		return errors;
	}

	public String getMessage() {
		return errors.stream().map(InputError::getMessage).collect(Collectors.joining("\n"));
	}

	public void validate() throws InputException {
		if (!isEmpty()) {
			LOG.warn(String.format("%s input error(s) occurred: %s", size(), errors));
			throw new InputException(this, errors.get(errors.size() - 1).getCause());
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy