Example usage for java.util Optional get

List of usage examples for java.util Optional get

Introduction

In this page you can find the example usage for java.util Optional get.

Prototype

public T get() 

Source Link

Document

If a value is present, returns the value, otherwise throws NoSuchElementException .

Usage

From source file:net.sf.jabref.logic.fulltext.ScienceDirect.java

@Override
public Optional<URL> findFullText(BibEntry entry) throws IOException {
    Objects.requireNonNull(entry);
    Optional<URL> pdfLink = Optional.empty();

    // Try unique DOI first
    Optional<DOI> doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build);

    if (doi.isPresent()) {
        // Available in catalog?
        try {/*from   w ww.  j ava  2 s  . co  m*/
            String sciLink = getUrlByDoi(doi.get().getDOI());

            if (!sciLink.isEmpty()) {
                // Retrieve PDF link
                Document html = Jsoup.connect(sciLink).ignoreHttpErrors(true).get();
                Element link = html.getElementById("pdfLink");

                if (link != null) {
                    LOGGER.info("Fulltext PDF found @ ScienceDirect.");
                    pdfLink = Optional.of(new URL(link.attr("pdfurl")));
                }
            }
        } catch (UnirestException e) {
            LOGGER.warn("ScienceDirect API request failed", e);
        }
    }
    return pdfLink;
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthDatapointMapperDateTimeUnitTests.java

public void testTimeFrameWhenItShouldBeSetCorrectly(String timezoneString, String expectedDateTime)
        throws IOException {

    JsonNode timeInfoNode = createResponseNodeWithTimeZone(timezoneString);
    Optional<TimeFrame> effectiveTimeFrameAsDateTime = getEffectiveTimeFrameAsDateTime(timeInfoNode);

    assertThat(effectiveTimeFrameAsDateTime.isPresent(), is(true));
    assertThat(effectiveTimeFrameAsDateTime.get().getDateTime(),
            equalTo(OffsetDateTime.parse(expectedDateTime)));
}

From source file:com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorPackager.java

public NugetParseResult createDetectCodeLocation(final File dependencyNodeFile) throws IOException {
    final String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
    final NugetInspection nugetInspection = gson.fromJson(text, NugetInspection.class);

    final List<DetectCodeLocation> codeLocations = new ArrayList<>();
    String projectName = "";
    String projectVersion = "";
    for (final NugetContainer it : nugetInspection.containers) {
        final Optional<NugetParseResult> possibleParseResult = createDetectCodeLocationFromNugetContainer(it);
        if (possibleParseResult.isPresent()) {
            final NugetParseResult result = possibleParseResult.get();
            if (StringUtils.isNotBlank(result.projectName)) {
                projectName = result.projectName;
                projectVersion = result.projectVersion;
            }//from  www  .  j a v a  2  s  . c  o m
            codeLocations.addAll(result.codeLocations);
        }
    }

    return new NugetParseResult(projectName, projectVersion, codeLocations);
}

From source file:dk.dma.ais.sentence.SentenceException.java

public String getPossibleProprietaryTag() {
    String possibleProprietaryTag = null;

    if (sentenceTrace != null) {
        Optional<String> stringOptional = sentenceTrace.stream()
                .filter(line -> ProprietaryFactory.isProprietaryTag(line)).reduce((p, c) -> c);
        if (stringOptional != null && stringOptional.isPresent()) {
            possibleProprietaryTag = stringOptional.get();
        }/* ww w  .  ja v a2s .c om*/
    }
    return possibleProprietaryTag;
}

From source file:io.gravitee.gateway.env.GatewayConfigurationTest.java

@Test
public void shouldReturnShardingTagsFromSystemProperty() {
    System.setProperty(GatewayConfiguration.SHARDING_TAGS_SYSTEM_PROPERTY, "public,private");
    gatewayConfiguration.afterPropertiesSet();

    Optional<List<String>> shardingTagsOpt = gatewayConfiguration.shardingTags();
    Assert.assertTrue(shardingTagsOpt.isPresent());

    List<String> shardingTags = shardingTagsOpt.get();
    Assert.assertEquals(2, shardingTags.size());
    Assert.assertEquals("public", shardingTags.get(0));
    Assert.assertEquals("private", shardingTags.get(1));
}

From source file:com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParserTest.java

@Test
public void testSpringFrameworkAop() throws IOException {
    final File file = new File("src/test/resources/gradle/spring-framework/spring_aop_dependencyGraph.txt");
    final GradleReportParser gradleReportParser = new GradleReportParser(new ExternalIdFactory());
    final Optional<DetectCodeLocation> result = gradleReportParser.parseDependencies(file);
    assertTrue(result.isPresent());/*from  w  w w.j  a  v a2  s.  c  o m*/
    System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(result.get()));
}

From source file:com.blackducksoftware.integration.hub.detect.detector.gradle.GradleReportParserTest.java

@Test
public void testImplementationsGraph() throws IOException {
    final File file = new File("src/test/resources/gradle/gradle_implementations_dependencyGraph.txt");
    final GradleReportParser gradleReportParser = new GradleReportParser(new ExternalIdFactory());
    final Optional<DetectCodeLocation> result = gradleReportParser.parseDependencies(file);
    assertTrue(result.isPresent());//from  www  . j a v a2 s.  c  o  m
    System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(result.get()));
}

From source file:com.devicehive.dao.UserDaoTest.java

public void testFindByName() throws Exception {
    UserVO user = new UserVO();
    Long id = 100L;/*from w w w  .  j  a  va 2 s .c o  m*/
    user.setId(id);
    user.setLogin("login");
    userDao.persist(user);

    Optional<UserVO> newUser = userDao.findByName("login");
    assertTrue(newUser.isPresent());
    assertEquals(id, newUser.get().getId());
}

From source file:io.gravitee.gateway.env.GatewayConfigurationTest.java

@Test
public void shouldReturnShardingTagsFromConfiguration() {
    Mockito.when(environment.getProperty(GatewayConfiguration.SHARDING_TAGS_SYSTEM_PROPERTY))
            .thenReturn("public,private");
    gatewayConfiguration.afterPropertiesSet();

    Optional<List<String>> shardingTagsOpt = gatewayConfiguration.shardingTags();
    Assert.assertTrue(shardingTagsOpt.isPresent());

    List<String> shardingTags = shardingTagsOpt.get();
    Assert.assertEquals(2, shardingTags.size());
    Assert.assertEquals("public", shardingTags.get(0));
    Assert.assertEquals("private", shardingTags.get(1));
}

From source file:com.linkedin.gradle.python.tasks.action.pip.PipWheelAction.java

private boolean doesWheelExist(PackageInfo packageInfo) {
    Optional<File> wheel = wheelCache.findWheel(packageInfo.getName(), packageInfo.getVersion(), pythonDetails);
    if (wheel.isPresent()) {
        File wheelFile = wheel.get();

        try {/*from   w  w  w  .ja v  a2s . c o m*/
            FileUtils.copyFile(wheelFile, new File(wheelExtension.getWheelCache(), wheelFile.getName()));
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        if (PythonHelpers.isPlainOrVerbose(project)) {
            logger.lifecycle("Skipping {}, in wheel cache {}", packageInfo.toShortHand(), wheelFile);
        }
        return true;
    }

    ConfigurableFileTree tree = project.fileTree(wheelExtension.getWheelCache(), action -> {
        String sanitizedName = packageInfo.getName().replace('-', '_');
        String sanitizedVersion = (packageInfo.getVersion() == null ? "unspecified" : packageInfo.getVersion())
                .replace('-', '_');
        action.include("**/" + sanitizedName + "-" + sanitizedVersion + "-*.whl");
    });

    if (tree.getFiles().size() >= 1) {
        logger.lifecycle("Skipping {} wheel - Installed", packageInfo.toShortHand());
        return true;
    }
    return false;
}