Example usage for java.util Optional ofNullable

List of usage examples for java.util Optional ofNullable

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public static <T> Optional<T> ofNullable(T value) 

Source Link

Document

Returns an Optional describing the given value, if non- null , otherwise returns an empty Optional .

Usage

From source file:org.basinmc.maven.plugins.minecraft.launcher.VersionIndex.java

/**
 * Returns the descriptor for a certain Minecraft version.
 *//*w w w.java 2s .co m*/
@Nonnull
public Optional<VersionDescriptor> getDescriptor(@Nonnull String id) {
    return Optional.ofNullable(this.maps.get(id));
}

From source file:de.sainth.recipe.backend.db.repositories.UserRepository.java

public Optional<String> getEncryptedPassword(String username) {
    return Optional.ofNullable(create.select(USERS.PASSWORD).from(USERS).where(USERS.NAME.eq(username))
            .fetchOneInto(String.class));
}

From source file:io.github.carlomicieli.footballdb.starter.pages.Table.java

/**
 * Returns the n-th row in the table, or <em>Optional.empty()</em> if the
 * column is not present./* w w w  .  ja v  a2s  . c om*/
 *
 * @param index the row number (starting from 1)
 * @return a row
 */
public Optional<Row> row(int index) {
    if (index > size.getLeft()) {
        return Optional.empty();
    }
    return Optional.ofNullable(rows.get(index - 1));
}

From source file:it.reply.orchestrator.service.security.OAuth2TokenService.java

/**
 * Retrieve the CLUES IAM information from the OAuth2 access token.
 * /*  w w w .ja  va2 s  . co m*/
 * @param accessToken
 *          the accessToken
 * @return the CLUES IAM information
 * @throws ParseException
 *           if the access token is not a valid JWT
 */
public Optional<OidcClientProperties> getCluesInfo(String accessToken) throws ParseException {
    if (!oidcProperties.isEnabled()) {
        throw new IllegalStateException("Security is not enabled");
    }
    String iss = JWTParser.parse(accessToken).getJWTClaimsSet().getIssuer();
    return Optional.ofNullable(oidcProperties.getIamConfiguration(iss))
            .map(configuration -> configuration.getClues());
}

From source file:com.orange.cloud.servicebroker.filter.core.filters.ServiceInstanceBindingFilterRunner.java

/**
 * Run all filters that should be processed after a service instance instance binding has been created.
 *
 * @param request details of a request to bind to a service instance binding.
 *///from w ww. j  ava 2  s  . c o  m
public void postBind(CreateServiceInstanceBindingRequest request,
        CreateServiceInstanceAppBindingResponse response) {
    Optional.ofNullable(createServiceInstanceBindingPostFilters).ifPresent(
            serviceBrokerFilters -> serviceBrokerFilters.forEach(filter -> filter.run(request, response)));
}

From source file:io.mapzone.arena.csw.catalog.CswMetadataBase.java

@Override
public Optional<Date> getModified() {
    return Optional.ofNullable(record().modified).map(v -> v.toGregorianCalendar().getTime());
}

From source file:nu.yona.server.rest.RestClientErrorHandler.java

private Optional<ErrorResponseDto> getYonaErrorResponse(ClientHttpResponse response) {
    try {// ww  w  . j  ava  2  s.  c  o m
        if (getStatusCode(response).series() == HttpStatus.Series.CLIENT_ERROR) {
            return Optional.ofNullable(objectMapper.readValue(response.getBody(), ErrorResponseDto.class));
        }
    } catch (IOException e) {
        // Ignore and just return empty
    }
    return Optional.empty();
}

From source file:org.basinmc.maven.plugins.minecraft.access.TransformationType.java

/**
 * Retrieves the type visibility./*  w w  w.  j a va2s . co  m*/
 */
@Nonnull
public Optional<Visibility> getVisibility() {
    return Optional.ofNullable(this.visibility);
}

From source file:org.rakam.analysis.retention.RetentionAnalyzerHttpService.java

@ApiOperation(value = "Execute query", authorizations = @Authorization(value = "read_key"), consumes = "text/event-stream", produces = "text/event-stream")
@GET//from   ww w .  j  a  v a2 s  .  c o  m
@IgnoreApi
@Path("/analyze")
public void analyzeRetention(RakamHttpRequest request) {
    queryService.handleServerSentQueryExecution(request, RetentionQuery.class,
            (project, query) -> retentionQueryExecutor.query(project, Optional.ofNullable(query.firstAction),
                    Optional.ofNullable(query.returningAction), query.dateUnit,
                    Optional.ofNullable(query.dimension), Optional.ofNullable(query.period), query.startDate,
                    query.endDate, query.timezone, query.approximate));
}

From source file:com.toptal.conf.SecurityUtils.java

/**
 * Actual Vaadin user./*  w  w w.  j  av  a 2s  . co  m*/
 * @param dao User dao.
 * @return User.
 */
private static Optional<User> actualUserVaadin(final UserDao dao) {
    Optional<User> result = Optional.empty();
    if (VaadinSession.getCurrent() != null) {
        final User user = VaadinSession.getCurrent().getAttribute(User.class);
        if (user != null) {
            result = Optional.ofNullable(dao.findOne(user.getId()));
        }
    }
    return result;
}