io.vavr.API.unchecked()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(237)

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

API.unchecked介绍

[英]Alias for CheckedFunction0#unchecked
[中]CheckedFunction0的别名#未选中

代码示例

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

  1. private static Optional<String> reveal(ConfigurationContext context, String captured) {
  2. return context.getSecretSources().stream()
  3. .map(source -> unchecked(() -> source.reveal(captured)).apply())
  4. .flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
  5. .findFirst();
  6. }

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

  1. private CNode getActualValue(CNode config, ConfigurationContext context) {
  2. return unchecked(() -> config.asMapping().entrySet().stream().findFirst()).apply()
  3. .map(entry -> {
  4. Mapping mapping = new Mapping();
  5. mapping.put(entry.getKey(), revealSourceOrGetValue(entry, context));
  6. return (CNode) mapping;
  7. }).orElse(config);
  8. }

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

  1. private String revealSourceOrGetValue(Map.Entry<String, CNode> entry, ConfigurationContext context) {
  2. String value = unchecked(() -> entry.getValue().asScalar().getValue()).apply();
  3. return SecretSourceResolver.resolve(context, value);
  4. }

代码示例来源: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: Tristan971/Lyrebird

  1. /**
  2. * Uploads the given media files to Twitter
  3. *
  4. * @param twitter The twitter instance to use for uploading
  5. * @param attachments The media files to upload
  6. *
  7. * @return The uploaded media files Twitter-side ids
  8. */
  9. private static List<Long> uploadMedias(final Twitter twitter, final List<File> attachments) {
  10. LOG.debug("Uploading media attachments {}", attachments);
  11. return attachments.stream()
  12. .map(unchecked((CheckedFunction1<File, UploadedMedia>) twitter::uploadMedia))
  13. .map(UploadedMedia::getMediaId)
  14. .collect(Collectors.toList());
  15. }

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

  1. @Cacheable("availableVersions")
  2. public List<LyrebirdVersion> getAllVersions() {
  3. final PathMatchingResourcePatternResolver versionsResourcesResolver = new PathMatchingResourcePatternResolver();
  4. try {
  5. final Resource[] versionResources = versionsResourcesResolver.getResources(VERSIONS_PATTERN);
  6. return Arrays.stream(versionResources)
  7. .map(unchecked(Resource::getInputStream))
  8. .map(unchecked(is -> objectMapper.readValue(is, LyrebirdVersion.class)))
  9. .sorted(Comparator.comparing(LyrebirdVersion::getBuildVersion).reversed())
  10. .collect(Collectors.toList());
  11. } catch (final IOException e) {
  12. throw new IllegalStateException("Can not load releases!", e);
  13. }
  14. }

代码示例来源:origin: io.jenkins/configuration-as-code

  1. private static Optional<String> reveal(ConfigurationContext context, String captured) {
  2. return context.getSecretSources().stream()
  3. .map(source -> unchecked(() -> source.reveal(captured)).apply())
  4. .flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
  5. .findFirst();
  6. }

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

  1. /**
  2. * Creates a user authentication request on Twitter side
  3. *
  4. * @return a tuple containing the URL for OTP, and the RequestToken to which this OTP will be bound to
  5. */
  6. public Tuple2<URL, RequestToken> newSession() {
  7. LOG.info("Requesting new Session!");
  8. final RequestToken requestToken = unchecked((CheckedFunction0<RequestToken>) this.twitter::getOAuthRequestToken)
  9. .apply();
  10. LOG.info("Got request token : {}", requestToken);
  11. return Tuple.of(
  12. unchecked((CheckedFunction0<URL>) (() -> new URL(requestToken.getAuthorizationURL()))).apply(),
  13. requestToken
  14. );
  15. }

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

  1. /**
  2. * Deserializes the credited works matching the {@link #CREDITS_RESOURCES_PATH} location pattern.
  3. *
  4. * @param objectMapper The object mapper used for deserialization
  5. * @param pmpr The {@link PathMatchingResourcePatternResolver} used for location pattern matching
  6. *
  7. * @return The list of deserialized credits files
  8. */
  9. private static List<CreditedWork> loadCreditsFiles(
  10. final ObjectMapper objectMapper,
  11. final PathMatchingResourcePatternResolver pmpr
  12. ) {
  13. return Try.of(() -> pmpr.getResources(CREDITS_RESOURCES_PATH))
  14. .toStream()
  15. .flatMap(Stream::of)
  16. .map(unchecked(Resource::getInputStream))
  17. .map(unchecked(cis -> objectMapper.readValue(cis, CreditedWork.class)))
  18. .toJavaList();
  19. }

相关文章