io.vavr.control.Either.getOrElseThrow()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中io.vavr.control.Either.getOrElseThrow()方法的一些代码示例,展示了Either.getOrElseThrow()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Either.getOrElseThrow()方法的具体详情如下:
包路径:io.vavr.control.Either
类名称:Either
方法名:getOrElseThrow

Either.getOrElseThrow介绍

[英]Gets the Right value or throws, if the projected Either is a Left.
[中]如果投影的值是左值,则获取或抛出右值。

代码示例

代码示例来源:origin: vavr-io/vavr

/**
 * Gets the Right value or throws, if the projected Either is a Left.
 *
 * @param <X>               a throwable type
 * @param exceptionFunction a function which creates an exception based on a Left value
 * @return the right value, if the underlying Either is a Right or else throws the exception provided by
 * {@code exceptionFunction} by applying the Left value.
 * @throws X if the projected Either is a Left
 */
public <X extends Throwable> R getOrElseThrow(Function<? super L, X> exceptionFunction) throws X {
  Objects.requireNonNull(exceptionFunction, "exceptionFunction is null");
  return either.getOrElseThrow(exceptionFunction);
}

代码示例来源:origin: io.vavr/vavr

/**
 * Gets the Right value or throws, if the projected Either is a Left.
 *
 * @param <X>               a throwable type
 * @param exceptionFunction a function which creates an exception based on a Left value
 * @return the right value, if the underlying Either is a Right or else throws the exception provided by
 * {@code exceptionFunction} by applying the Left value.
 * @throws X if the projected Either is a Left
 */
public <X extends Throwable> R getOrElseThrow(Function<? super L, X> exceptionFunction) throws X {
  Objects.requireNonNull(exceptionFunction, "exceptionFunction is null");
  return either.getOrElseThrow(exceptionFunction);
}

代码示例来源:origin: com.github.robozonky/robozonky-app

/**
 * Calling this method may cause a background operation to re-fetch all the data from Zonky.
 * @return
 */
private RemoteData getRemotePortfolio() {
  return portfolio.get().getOrElseThrow(t -> new IllegalStateException("Failed fetching remote portfolio.", t));
}

代码示例来源:origin: com.github.robozonky/robozonky-app

@Override
  public PortfolioOverview getOverview() {
    return portfolioOverview.get()
        .getOrElseThrow(t -> new IllegalStateException("Failed calculating portfolio overview.", t));
  }
}

代码示例来源:origin: RoboZonky/robozonky

@Override
  public PortfolioOverview getOverview() {
    return portfolioOverview.get()
        .getOrElseThrow(t -> new IllegalStateException("Failed calculating portfolio overview.", t));
  }
}

代码示例来源:origin: RoboZonky/robozonky

@Override
public ZonkyApiToken get() {
  if (isClosed.get()) {
    throw new IllegalStateException("Token already closed.");
  }
  return token.get().getOrElseThrow(t -> new IllegalStateException("Token retrieval failed.", t));
}

代码示例来源:origin: RoboZonky/robozonky

public static Scheduler inBackground() {
  return BACKGROUND_SCHEDULER.get().getOrElseThrow(() -> new IllegalStateException("Impossible."));
}

代码示例来源:origin: com.github.robozonky/robozonky-app

@Override
public Map<Rating, BigDecimal> getAtRisk() {
  return atRisk.get().getOrElseThrow(t -> new IllegalStateException("Failed fetching remote risk data.", t));
}

代码示例来源:origin: RoboZonky/robozonky

@Override
public Map<Rating, BigDecimal> getAtRisk() {
  return atRisk.get().getOrElseThrow(t -> new IllegalStateException("Failed fetching remote risk data.", t));
}

代码示例来源:origin: RoboZonky/robozonky

private DelayedFiring getDelayedFiring() {
  return delayedFiring.get().getOrElseThrow(() -> new IllegalStateException("Can not happen."));
}

代码示例来源:origin: com.github.robozonky/robozonky-common

private static Scheduler actuallyGetBackgroundScheduler() {
  return BACKGROUND_SCHEDULER.get().getOrElseThrow(() -> new IllegalStateException("Impossible."));
}

代码示例来源:origin: com.github.robozonky/robozonky-app

private DelayedFiring getDelayedFiring() {
  return delayedFiring.get().getOrElseThrow(() -> new IllegalStateException("Can not happen."));
}

代码示例来源:origin: RoboZonky/robozonky

private RemoteData getRemotePortfolio() {
  return portfolio.get().getOrElseThrow(t -> new IllegalStateException("Failed fetching remote portfolio.", t));
}

相关文章