Example usage for java.util Optional of

List of usage examples for java.util Optional of

Introduction

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

Prototype

public static <T> Optional<T> of(T value) 

Source Link

Document

Returns an Optional describing the given non- null value.

Usage

From source file:spring.travel.site.services.news.NewsService.java

public CompletableFuture<Optional<List<NewsItem>>> news() {
    List<NewsItem> newsItems = newsCache.getIfPresent(newsServiceUrl);
    if (newsItems != null) {
        return some(newsItems);
    }/*from  ww w  .  ja v a2s .c  om*/
    return client
            .get(newsServiceUrl, request -> request.getHeaders().add("Accept", "text/xml"),
                    response -> Optional.of(newsDigester.from(response.getResponseBodyAsStream())))
            .handle(withFallback(Optional.<List<NewsItem>>empty()))
            .whenComplete((items, t) -> items.ifPresent(it -> {
                if (it.size() > 0) {
                    newsCache.put(newsServiceUrl, it);
                }
            }));
}

From source file:com.facebook.buck.util.unarchive.Untar.java

public static Untar zstdUnarchiver() {
    return new Untar(Optional.of(CompressorStreamFactory.ZSTANDARD));
}

From source file:io.github.resilience4j.circuitbreaker.monitoring.health.CircuitBreakerHealthIndicator.java

@Override
public Health health() {
    return Optional.of(circuitBreaker).map(this::mapBackendMonitorState).orElse(Health.up().build());
}

From source file:fi.helsinki.opintoni.service.UserNotificationServiceTest.java

@Test
public void thatUserNotificationsAreReturned() {
    defaultTeacherRequestChain().defaultCoursesWithImplementationsAndRealisations()
            .activity("teachernotifications.json");

    List<UserNotificationDto> userNotifications = userNotificationService.getUserNotifications(1L,
            Optional.empty(), Optional.of(TestConstants.TEACHER_NUMBER), Locale.ENGLISH);

    assertThat(userNotifications).hasSize(2);

    UserNotificationDto userNotificationDto = userNotifications.get(0);
    assertThat(userNotificationDto.notificationId).isEqualTo("3");
    assertThat(userNotificationDto.message).isEqualTo("has written a message");
    assertThat(userNotificationDto.read).isTrue();

    userNotificationDto = userNotifications.get(1);
    assertThat(userNotificationDto.notificationId).isEqualTo("4");
    assertThat(userNotificationDto.message).isEqualTo("has removed an event");
    assertThat(userNotificationDto.read).isFalse();
}

From source file:org.trustedanalytics.cloud.cc.api.CcOrg.java

@JsonIgnore
public String getName() {
    Optional<CcOrg> org = Optional.of(this);
    return org.map(CcOrg::getEntity).map(CcOrgEntity::getName).orElse(null);
}

From source file:nu.yona.server.messaging.service.DisclosureResponseMessageDto.java

public static DisclosureResponseMessageDto createInstance(DisclosureResponseMessage messageEntity,
        SenderInfo senderInfo) {/*from w w  w .  j  a  v a 2 s  .c o  m*/
    GoalConflictMessage targetGoalConflictMessage = messageEntity.getTargetGoalConflictMessage();
    return new DisclosureResponseMessageDto(messageEntity.getId(), messageEntity.getCreationTime(),
            messageEntity.isRead(), senderInfo, messageEntity.getStatus(), messageEntity.getMessage(),
            Optional.of(targetGoalConflictMessage.getId()), targetGoalConflictMessage.getGoal().getId(),
            targetGoalConflictMessage.getActivity().getStartTime().toLocalDate());
}

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

@Override
protected Optional<String> getMeasureUnitNodeName() {
    return Optional.of("BPUnit");
}

From source file:alfio.manager.EuVatChecker.java

static BiFunction<ConfigurationManager, OkHttpClient, Optional<VatDetail>> performCheck(String vatNr,
        String countryCode, int organizationId) {
    return (configurationManager, client) -> {
        if (StringUtils.isNotEmpty(vatNr) && StringUtils.length(countryCode) == 2
                && checkingEnabled(configurationManager, organizationId)) {
            Request request = new Request.Builder().url(apiAddress(configurationManager) + "?country="
                    + countryCode.toUpperCase() + "&number=" + vatNr).get().build();
            try (Response resp = client.newCall(request).execute()) {
                if (resp.isSuccessful()) {
                    return Optional.of(getVatDetail(resp, vatNr, countryCode,
                            organizerCountry(configurationManager, organizationId)));
                } else {
                    return Optional.empty();
                }/*from w w  w  .java2 s  .co m*/
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return Optional.empty();
    };
}

From source file:com.github.steveash.guavate.GuavateTest.java

@Test
public void test_stream_Optional() {
    Optional<String> optional = Optional.of("foo");
    List<String> test1 = Guavate.stream(optional).collect(Collectors.toList());
    assertEquals(test1, ImmutableList.of("foo"));

    Optional<String> empty = Optional.empty();
    List<String> test2 = Guavate.stream(empty).collect(Collectors.toList());
    assertEquals(test2, ImmutableList.of());
}

From source file:com.teradata.tempto.query.JdbcConnectivityParamsState.java

@Override
public Optional<String> getName() {
    return Optional.of(name);
}