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

com.dslplatform.compiler.client.Either Maven / Gradle / Ivy

package com.dslplatform.compiler.client;

public final class Either {
	private final T value;
	private final Exception error;

	private Either(final T value, final Exception error) {
		this.value = value;
		this.error = error;
	}

	public boolean isSuccess() {
		return error == null;
	}

	public T get() {
		return value;
	}

	public Exception whyNot() {
		return error;
	}

	public String explainError() { return error.getMessage(); }

	public static  Either success(final S value) {
		return new Either(value, null);
	}

	public static  Either fail(final String error) {
		return new Either(null, new Exception(error));
	}

	public static  Either fail(final Exception error) {
		return new Either(null, error);
	}

	public static  Either fail(final String description, final Exception error) {
		return new Either(null, new Exception(description, error));
	}
}