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

x33g5p2x  于2022-01-30 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(191)

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

Try.getOrElseThrow介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

private GeneratedItems generateFromScript(String script, JenkinsJobManagement management) {
  return unchecked(() ->
      Try(() -> new JenkinsDslScriptLoader(management).runScript(script))
          .getOrElseThrow(t -> new ConfiguratorException(this, "Failed to execute script with hash " + script.hashCode(), t))).apply();
}

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

private String getScriptFromSource(CNode source, ConfigurationContext context, Configurator<ScriptSource> configurator) {
    return unchecked(() ->
        Try(() -> configurator.configure(source, context))
            .getOrElseThrow(t -> new ConfiguratorException(this, "Failed to retrieve job-dsl script", t))
            .getScript()).apply();
  }
}

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

public static void writeOutProperties(final Properties properties, final File target) {
  Try.withResources(() -> Files.newBufferedWriter(target.toPath(), Defaults.CHARSET))
      .of(w -> {
        properties.store(w, Defaults.ROBOZONKY_USER_AGENT);
        LOGGER.debug("Written properties to {}.", target);
        return null;
      })
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

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

public static void writeOutProperties(final Properties properties, final File target) {
  Try.withResources(() -> Files.newBufferedWriter(target.toPath(), Defaults.CHARSET))
      .of(w -> {
        properties.store(w, Defaults.ROBOZONKY_USER_AGENT);
        LOGGER.debug("Written properties to {}.", target);
        return null;
      })
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

代码示例来源:origin: Tristan971/Lyrebird

@Cacheable(value = "userFromUserId", sync = true)
public User showUser(final long userId) {
  return sessionManager.doWithCurrentTwitter(
      twitter -> twitter.showUser(userId)
  ).getOrElseThrow(
      err -> new IllegalStateException("Cannot find user with id " + userId, err)
  );
}

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

@Override
protected String getLatestSource() {
  return Try.withResources(url::openStream)
      .of(s -> IOUtils.toString(s, Defaults.CHARSET))
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

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

private GoogleClientSecrets createClientSecrets() {
  final byte[] key = secrets.get();
  return Try.withResources(() -> new ByteArrayInputStream(key))
      .of(s -> GoogleClientSecrets.load(Util.JSON_FACTORY, new InputStreamReader(s)))
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

代码示例来源:origin: Tristan971/Lyrebird

/**
 * @return the updated screen name of the current user
 */
private String getCurrentScreenName() {
  return sessionManager.getCurrentTwitter()
             .mapTry(Twitter::getScreenName)
             .getOrElseThrow(err -> new IllegalStateException("Current user unavailable!", err));
}

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

@Override
protected String getLatestSource() {
  return Try.withResources(url::openStream)
      .of(s -> IOUtils.toString(s, Defaults.CHARSET))
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

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

private GoogleClientSecrets createClientSecrets() {
  final byte[] key = secrets.get();
  return Try.withResources(() -> new ByteArrayInputStream(key))
      .of(s -> GoogleClientSecrets.load(Util.JSON_FACTORY, new InputStreamReader(s)))
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

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

/**
   * Persist whatever operations that have been made using this API. Unless this method is called, no other methods
   * have effect.
   * @param secret Password to persist the changes with.
   */
  public void save(final char... secret) {
    this.password = secret.clone();
    Try.withResources(() -> new BufferedOutputStream(new FileOutputStream(this.keyStoreFile)))
        .of(os -> {
          this.keyStore.store(os, secret);
          this.dirty.set(false);
          return null;
        })
        .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
  }
}

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

/**
   * Persist whatever operations that have been made using this API. Unless this method is called, no other methods
   * have effect.
   * @param secret Password to persist the changes with.
   */
  public void save(final char... secret) {
    this.password = secret.clone();
    Try.withResources(() -> new BufferedOutputStream(new FileOutputStream(this.keyStoreFile)))
        .of(os -> {
          this.keyStore.store(os, secret);
          this.dirty.set(false);
          return null;
        })
        .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
  }
}

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

@Override
protected String getLatestSource() {
  return Try.withResources(() -> UpdateMonitor.getMavenCentralData(this.groupId, this.artifactId,
                                   this.mavenCentralHostname))
      .of(s -> IOUtils.toString(s, Defaults.CHARSET))
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

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

@Override
protected String getLatestSource() {
  return Try.withResources(() -> UpdateMonitor.getMavenCentralData(this.groupId, this.artifactId,
                                   this.mavenCentralHostname))
      .of(s -> IOUtils.toString(s, Defaults.CHARSET))
      .getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

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

@Override
public ReturnCode apply(final Lifecycle lifecycle) {
  return Try.of(() -> {
    final Scheduler s = Scheduler.inBackground();
    // schedule the tasks
    scheduleJobs(s);
    scheduleDaemons(s);
    // block until request to stop the app is received
    lifecycle.suspend();
    LOGGER.trace("Request to stop received.");
    // signal the end of standard operation
    return ReturnCode.OK;
  }).getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

代码示例来源:origin: Tristan971/Lyrebird

private CompletionStage<Stage> loadCreditsStage() {
  return easyFxml.loadNode(CREDITS_VIEW)
          .orExceptionPane()
          .map(pane -> Stages.stageOf("Credits", pane))
          .getOrElseThrow((Function<? super Throwable, ? extends RuntimeException>) RuntimeException::new);
}

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

@Override
public ReturnCode apply(final Lifecycle lifecycle) {
  scheduleJobs(Scheduler.inBackground());
  return Try.withResources(() -> Schedulers.INSTANCE.create(1, THREAD_FACTORY))
      .of(executor -> {
        // schedule the tasks
        scheduleDaemons(executor);
        // block until request to stop the app is received
        lifecycle.suspend();
        LOGGER.trace("Request to stop received.");
        // signal the end of standard operation
        return ReturnCode.OK;
      }).getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
}

代码示例来源:origin: Tristan971/Lyrebird

/**
 * @return The {@link Relationship} between the current user in the direction of the {@link #targetUserProp}.
 */
private Relationship getRelationship() {
  return sessionManager.doWithCurrentTwitter(
      twitter -> sessionManager.currentSessionProperty()
                   .getValue()
                   .getTwitterUser()
                   .mapTry(us -> twitter.showFriendship(
                       us.getId(),
                       targetUserProp.getValue().getId()
                   )).get()
  ).getOrElseThrow((Function<? super Throwable, IllegalStateException>) IllegalStateException::new);
}

代码示例来源:origin: org.janusgraph/janusgraph-cql

@Override
  public KeyIterator getKeys(final SliceQuery query, final StoreTransaction txh) throws BackendException {
    if (this.storeManager.getFeatures().hasOrderedScan()) {
      throw new PermanentBackendException("This operation is only allowed when a random partitioner (md5 or murmur3) is used.");
    }

    return Try.of(() -> new CQLResultSetKeyIterator(
        query,
        this.getter,
        this.session.execute(this.getKeysAll.bind()
            .setBytes(SLICE_START_BINDING, query.getSliceStart().asByteBuffer())
            .setBytes(SLICE_END_BINDING, query.getSliceEnd().asByteBuffer())
            .setFetchSize(this.storeManager.getPageSize())
            .setConsistencyLevel(getTransaction(txh).getReadConsistencyLevel()))))
        .getOrElseThrow(EXCEPTION_MAPPER);
  }
}

代码示例来源:origin: org.janusgraph/janusgraph-cql

@Override
public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh) throws BackendException {
  final Future<EntryList> result = Future.fromJavaFuture(
      this.executorService,
      this.session.executeAsync(this.getSlice.bind()
          .setBytes(KEY_BINDING, query.getKey().asByteBuffer())
          .setBytes(SLICE_START_BINDING, query.getSliceStart().asByteBuffer())
          .setBytes(SLICE_END_BINDING, query.getSliceEnd().asByteBuffer())
          .setInt(LIMIT_BINDING, query.getLimit())
          .setConsistencyLevel(getTransaction(txh).getReadConsistencyLevel())))
      .map(resultSet -> fromResultSet(resultSet, this.getter));
  interruptibleWait(result);
  return result.getValue().get().getOrElseThrow(EXCEPTION_MAPPER);
}

相关文章