public static <T, E> Validation<T, E> success(T value) { return new Validation<>(value, null); }
public boolean isError() { return !isSuccess(); }
/** If this is a successful result, returns the value. * You should always check for {@link #isSuccess() isSuccess} before calling this method. * * @return error value if defined */ public E getError() { if (!isError()) throw new IllegalStateException("Can't access error value of a successful result."); return error; }
@Override public String toString() { return this.getClass().getCanonicalName() + "{" + super.toString() + "}"; } }
@Override public T getValue() { if (!isSuccess()) throw getError(); return super.getValue(); }
/** If this is a successful result, returns the value. * You should always check for {@link #isSuccess() isSuccess} before calling this method. * * @return the value if present */ public T getValue() { if (isError()) throw new IllegalStateException("Can't access value of an erroneous result."); return value; }
public boolean isError() { return !isSuccess(); }
public static <T, E> Validation<T, E> success(T value) { return new Validation<>(value, null); }
/** If this is a successful result, returns the value. * You should always check for {@link #isSuccess() isSuccess} before calling this method. * * @return the value if present */ public T getValue() { if (!isSuccess()) throw new IllegalStateException("Can't access value of an erroneous result."); return value; }
/** If this is a successful result, returns the value. * You should always check for {@link #isSuccess() isSuccess} before calling this method. * * @return error value if defined */ public E getError() { if (isSuccess()) throw new IllegalStateException("Can't access error value of a successful result."); return error; }