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.thinkbiganalytics.metadata.modeshape.common.JcrPropertiesEntity.java

public Optional<JcrProperties> getPropertiesObject() {
    try {//from   w  ww .ja v  a2s .  co  m
        return Optional.ofNullable(JcrUtil.getJcrObject(this.node, PROPERTIES_NAME, JcrProperties.class));
    } catch (AccessControlException e) {
        return Optional.empty();
    }
}

From source file:io.github.carlomicieli.footballdb.starter.parsers.Parser.java

protected static Optional<String> valueFromChild(Element e, int index) {
    Elements children = e.children();
    if (index > children.size())
        return Optional.empty();

    return Optional.ofNullable(children.get(index).text());
}

From source file:com.nestedbird.modules.facebookreader.FacebookReader.java

/**
 * Gets id from url./*from w w w  .j a  va  2  s  .c  om*/
 *
 * @param url the url
 * @return the id from url
 */
public String getIdFromUrl(final String url) {
    final FacebookId facebookId = request(encodeUrl(url), FacebookId.class);

    return Optional.ofNullable(facebookId).map(FacebookId::getId).orElse(null);
}

From source file:com.thinkbiganalytics.metadata.api.event.feed.FeedChange.java

public Optional<String> getFeedName() {
    return Optional.ofNullable(feedName);
}

From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebRequestMappingMetadata.java

public Optional<String> path() {
    return Optional.ofNullable(mapping).map(m -> m.value()).filter(m -> m.length == 1).map(m -> m[0])
            .filter(p -> !p.isEmpty());
}

From source file:fi.hsl.parkandride.front.ReportController.java

@RequestMapping(method = POST, value = REPORT, consumes = APPLICATION_JSON_VALUE, produces = MEDIA_TYPE_EXCEL)
public ResponseEntity<?> report(@NotNull @PathVariable(REPORT_ID) String reportId,
        @RequestBody ReportParameters parameters, User currentUser) {
    log.info("report({})", reportId);
    byte[] report = Optional.ofNullable(reporters.get(reportId)).get().generateReport(currentUser, parameters);
    return ok().header(CONTENT_DISPOSITION, "attachment; filename=\"" + reportId + "\"").body(report);
}

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

@Override
public Optional<User> findByUsername(String username) throws TechnicalException {
    RedisUser redisUser = userRedisRepository.find(username);
    return Optional.ofNullable(convert(redisUser));
}

From source file:com.mattjtodd.coherence.CoherenceCache.java

@Override
public <T> T get(Object key, Class<T> type) {
    return Optional.ofNullable(namedCache.get(key)).map(type::cast).orElse(null);
}

From source file:com.github.mrenou.jacksonatic.internal.mapping.method.MethodMappingInternal.java

public String getMappedName() {
    return Optional.ofNullable(annotations.get(JsonProperty.class))
            .map(annotation -> ((JsonProperty) annotation).value())
            .filter(name1 -> name1 != null && !name1.isEmpty()).orElse(methodSignature.name);
}

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

/**
 * Retrieves the mappings for a certain type (if any).
 *///from ww w  .  j  a  v  a  2 s  . c  o  m
@Nonnull
public Optional<TransformationType> getTypeMappings(@Nonnull String type) {
    // unify class name to simplify things for our callee
    if (type.endsWith(".java")) {
        type = type.substring(0, type.length() - 5);
    }

    type = type.replace("/", ".");
    return Optional.ofNullable(this.map.get(type));
}