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:com.spotify.ffwd.signalfx.SignalFxOutputPlugin.java

@JsonCreator
public SignalFxOutputPlugin(@JsonProperty("sourceName") String sourceName,
        @JsonProperty("authToken") String authToken,
        @JsonProperty("flushInterval") Optional<Long> flushInterval,
        @JsonProperty("batching") Optional<Batching> batching, @JsonProperty("soTimeout") Integer soTimeout,
        @JsonProperty("filter") Optional<Filter> filter) {
    super(filter, Batching.from(flushInterval, batching, Optional.of(DEFAULT_FLUSH_INTERVAL)));
    this.sourceName = Optional.ofNullable(sourceName).orElse(DEFAULT_SOURCE_NAME);
    this.authToken = Optional.ofNullable(authToken)
            .orElseThrow(() -> new IllegalArgumentException("authToken: must be defined"));
    this.soTimeout = Optional.ofNullable(soTimeout).orElse(DEFAULT_SO_TIMEOUT);
}

From source file:de.perdian.commons.i18n.polyglot.PolyglotImpl.java

private Map<Method, PolyglotInvocationInfo> createInvocationInfoMap() {

    PolyglotConfiguration configuration = this.getInstanceClass().getAnnotation(PolyglotConfiguration.class);
    PolyglotKeyGenerator keyGenerator = new PolyglotKeyGenerator();
    keyGenerator/*from   ww  w . j  a  v a  2s  .c om*/
            .setPrefix(Optional.ofNullable(configuration).map(PolyglotConfiguration::keyPrefix).orElse(null));
    keyGenerator
            .setPostfix(Optional.ofNullable(configuration).map(PolyglotConfiguration::keyPostfix).orElse(null));

    Map<Method, PolyglotInvocationInfo> resultMap = new HashMap<>();
    this.appendInvocationInfos(resultMap, this.getInstanceClass(), keyGenerator);
    return resultMap;

}

From source file:eu.agilejava.snoop.client.SnoopProducer.java

private String readProperty(final String key, Map<String, Object> snoopConfig) {

    String property = Optional.ofNullable(System.getProperty(key)).orElseGet(() -> {
        String envProp = Optional.ofNullable(System.getenv(key)).orElseGet(() -> {
            String confProp = Optional.ofNullable(snoopConfig.get(key)).orElseThrow(() -> {
                return new SnoopConfigurationException(
                        key + " must be configured either in application.yml or as env or system property");
            }).toString();/*ww  w .ja  va2s.co  m*/
            return confProp;
        });
        return envProp;
    });

    return property;
}

From source file:org.apache.ambari.view.web.service.PackageServiceImpl.java

@Override
public Optional<ApplicationConfig> getApplicationConfig(Long versionId) {
    PackageVersion version = packageVersionRepository.findOne(versionId);
    if (version == null)
        return Optional.empty();
    return Optional.ofNullable(version.getConfig());
}

From source file:keywhiz.service.daos.SecretContentDAO.java

public Optional<SecretContent> getSecretContentById(long id) {
    SecretsContentRecord r = dslContext.fetchOne(SECRETS_CONTENT, SECRETS_CONTENT.ID.eq(id));
    return Optional.ofNullable(r).map(secretContentMapper::map);
}

From source file:com.netflix.conductor.server.ConductorConfig.java

@Override
public String getProperty(String key, String defaultValue) {
    return Optional.ofNullable(System.getProperty(key)).orElse(defaultValue);
}

From source file:com.devicehive.dao.riak.UserDaoRiakImpl.java

@Override
public Optional<UserVO> findByName(String name) {
    RiakUser riakUser = findBySecondaryIndex("login", name, USER_NS, RiakUser.class);
    RiakUser.convertToVo(riakUser);// ww  w .ja v a  2s  .com
    return Optional.ofNullable(RiakUser.convertToVo(riakUser));
}

From source file:org.rakam.analysis.funnel.FunnelAnalyzerHttpService.java

@ApiOperation(value = "Execute query", request = FunnelQuery.class, consumes = "text/event-stream", produces = "text/event-stream", authorizations = @Authorization(value = "read_key"))

@GET/*from w  ww .ja  v  a  2 s.  co  m*/
@IgnoreApi
@Path("/analyze")
public void analyzeFunnel(RakamHttpRequest request) {
    queryService.handleServerSentQueryExecution(request, FunnelQuery.class,
            (project, query) -> funnelQueryExecutor.query(project, query.steps,
                    Optional.ofNullable(query.dimension), query.startDate, query.endDate,
                    Optional.ofNullable(query.window), query.timezone));
}

From source file:alfio.manager.location.DefaultLocationManager.java

@Override
@Cacheable// ww w  .ja  v a 2s .  com
public TimeZone getTimezone(String latitude, String longitude) {
    return Optional
            .ofNullable(
                    TimeZoneApi
                            .getTimeZone(getApiContext(),
                                    new LatLng(Double.valueOf(latitude), Double.valueOf(longitude)))
                            .awaitIgnoreError())
            .orElseThrow(() -> new LocationNotFound(String
                    .format("No TimeZone found for location having coordinates: %s,%s", latitude, longitude)));

}

From source file:ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl.java

@Override
public Optional<Serializable> getDefaultValue(String metacardTypeName, String attributeName) {
    notNull(metacardTypeName, "The metacard type name cannot be null.");
    notNull(attributeName, "The attribute name cannot be null.");

    final Serializable globalDefault = globalDefaults.get(attributeName);
    final Serializable metacardDefault = metacardDefaults.getOrDefault(metacardTypeName, Collections.emptyMap())
            .get(attributeName);//from   w  ww.ja  v a 2s . c  om
    return Optional.ofNullable(metacardDefault != null ? metacardDefault : globalDefault);
}