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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. @Override
  2. public ReturnCode apply(final Lifecycle lifecycle) {
  3. return Try.of(() -> {
  4. final Scheduler s = Scheduler.inBackground();
  5. // schedule the tasks
  6. scheduleJobs(s);
  7. scheduleDaemons(s);
  8. // block until request to stop the app is received
  9. lifecycle.suspend();
  10. LOGGER.trace("Request to stop received.");
  11. // signal the end of standard operation
  12. return ReturnCode.OK;
  13. }).getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new);
  14. }

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

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

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

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

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

  1. /**
  2. * @return The {@link Relationship} between the current user in the direction of the {@link #targetUserProp}.
  3. */
  4. private Relationship getRelationship() {
  5. return sessionManager.doWithCurrentTwitter(
  6. twitter -> sessionManager.currentSessionProperty()
  7. .getValue()
  8. .getTwitterUser()
  9. .mapTry(us -> twitter.showFriendship(
  10. us.getId(),
  11. targetUserProp.getValue().getId()
  12. )).get()
  13. ).getOrElseThrow((Function<? super Throwable, IllegalStateException>) IllegalStateException::new);
  14. }

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

  1. @Override
  2. public KeyIterator getKeys(final SliceQuery query, final StoreTransaction txh) throws BackendException {
  3. if (this.storeManager.getFeatures().hasOrderedScan()) {
  4. throw new PermanentBackendException("This operation is only allowed when a random partitioner (md5 or murmur3) is used.");
  5. }
  6. return Try.of(() -> new CQLResultSetKeyIterator(
  7. query,
  8. this.getter,
  9. this.session.execute(this.getKeysAll.bind()
  10. .setBytes(SLICE_START_BINDING, query.getSliceStart().asByteBuffer())
  11. .setBytes(SLICE_END_BINDING, query.getSliceEnd().asByteBuffer())
  12. .setFetchSize(this.storeManager.getPageSize())
  13. .setConsistencyLevel(getTransaction(txh).getReadConsistencyLevel()))))
  14. .getOrElseThrow(EXCEPTION_MAPPER);
  15. }
  16. }

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

  1. @Override
  2. public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh) throws BackendException {
  3. final Future<EntryList> result = Future.fromJavaFuture(
  4. this.executorService,
  5. this.session.executeAsync(this.getSlice.bind()
  6. .setBytes(KEY_BINDING, query.getKey().asByteBuffer())
  7. .setBytes(SLICE_START_BINDING, query.getSliceStart().asByteBuffer())
  8. .setBytes(SLICE_END_BINDING, query.getSliceEnd().asByteBuffer())
  9. .setInt(LIMIT_BINDING, query.getLimit())
  10. .setConsistencyLevel(getTransaction(txh).getReadConsistencyLevel())))
  11. .map(resultSet -> fromResultSet(resultSet, this.getter));
  12. interruptibleWait(result);
  13. return result.getValue().get().getOrElseThrow(EXCEPTION_MAPPER);
  14. }

相关文章