/** * Constructs an Either containing a left value. * * @param left The left value to store in the either * @param <L> The type of the left value * @param <R> The type of the right value * * @return An Either wrapping the left value */ public static <L, R> Either<L, R> left(L left) { return new Either<>(left, null, true); }
/** * Returns the Left value wrapped in this Either. * * @return The Left value wrapped in this Either * * @throws UnsupportedOperationException If this Either wraps a Right value instead */ public L getLeft() { if (!isLeft()) { LOG.error(String.format(ErrorMessageFormat.EITHER_ERROR_LEFT_OF_RIGHT.getLoggingFormat(), this)); throw new UnsupportedOperationException(ErrorMessageFormat.EITHER_ERROR_LEFT_OF_RIGHT.format(this)); } return left; }
payloadEmitter = Observable.just(Either.<PreResponse, JobRow>right(jobMetadata)).publish(); } else if (asyncAfter == DataApiRequest.SYNCHRONOUS_ASYNC_AFTER_VALUE) { payloadEmitter = queryResultsEmitter.map(Either::<PreResponse, JobRow>left).publish(); asyncAfter, TimeUnit.MILLISECONDS, Observable.fromCallable(() -> Either.right(jobMetadata))
/** * Returns the Right value wrapped in this Either. * * @return The Right value wrapped in this Either * * @throws UnsupportedOperationException If this Either wraps a Left value instead */ public R getRight() { if (isLeft()) { LOG.error(String.format(ErrorMessageFormat.EITHER_ERROR_RIGHT_OF_LEFT.getLoggingFormat(), this)); throw new UnsupportedOperationException(ErrorMessageFormat.EITHER_ERROR_RIGHT_OF_LEFT.format(this)); } return right; } }
/** * Constructs an Either containing a right value. * * @param right The right value to store in the either * @param <L> The type of the left value * @param <R> The type of the right value * * @return An Either wrapping the right value */ public static <L, R> Either<L, R> right(R right) { return new Either<>(null, right, false); }