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:io.gravitee.repository.redis.management.RedisGroupRepository.java

@Override
public Optional<Group> findById(String groupId) throws TechnicalException {
    return Optional.ofNullable(convert(internalRepository.find(groupId)));
}

From source file:com.antonjohansson.elasticsearchshell.session.Session.java

public Optional<Connection> getOptionalConnection() {
    return Optional.ofNullable(connection);
}

From source file:io.gravitee.repository.redis.management.RedisTagRepository.java

@Override
public Optional<Tag> findById(final String tagId) throws TechnicalException {
    final RedisTag redisTag = tagRedisRepository.findById(tagId);
    return Optional.ofNullable(convert(redisTag));
}

From source file:fr.mtlx.odm.spring.SpringSessionImpl.java

SpringSessionImpl(final SpringSessionFactoryImpl sessionFactory, final CacheFactory sessionCacheFactory,
        final CacheFactory contextCacheFactory) {
    super(sessionCacheFactory);

    this.sessionFactory = sessionFactory;

    this.contextCache = new TypeSafeCache<DirContextOperations>(DirContextOperations.class,
            Optional.ofNullable(contextCacheFactory.getCache()).orElse(new NoCache()));
}

From source file:io.github.retz.web.JobRequestHandler.java

static void setScheduler(RetzScheduler sched) {
    scheduler = Optional.ofNullable(sched);
}

From source file:io.gravitee.repository.redis.management.RedisApiKeyRepository.java

@Override
public Optional<ApiKey> findById(String apiKey) throws TechnicalException {
    return Optional.ofNullable(convert(apiKeyRedisRepository.find(apiKey)));
}

From source file:io.gravitee.repository.redis.management.RedisViewRepository.java

@Override
public Optional<View> findById(final String viewId) throws TechnicalException {
    final RedisView redisView = viewRedisRepository.findById(viewId);
    return Optional.ofNullable(convert(redisView));
}

From source file:org.zalando.baigan.etcd.service.EtcdClient.java

public final Optional<String> get(@Nonnull final String key) {
    try {/*from  w w  w.ja  v  a  2s  .co m*/
        final URL url = new URL(etcdUrl + key);

        final KeyResultNode resultNode = mapper.readValue(url, KeyResultNode.class);
        final String response = resultNode.getNode().getValue();

        return Optional.ofNullable(response);
    } catch (IOException e) {
        LOG.warn("There was an exception trying to get key: " + key, e);
    } catch (NullPointerException npe) {
        LOG.warn("There was an exception trying to get key: " + key);
    }
    return Optional.empty();
}

From source file:org.obiba.mica.micaConfig.service.EntityConfigService.java

public Optional<T> findPartial() {
    return Optional.ofNullable(findOrCreateDefaultForm());
}

From source file:com.yahoo.parsec.web.ParsecServletRequestWrapper.java

public String getContent() throws UnsupportedEncodingException {
    String charset = Optional.ofNullable(getCharacterEncoding()).orElse("UTF-8");
    return contentStream.toString(charset);
}