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:com.github.rutledgepaulv.qbuilders.structures.FieldPath.java

public Optional<FieldPath> getParentPath() {
    if (chain.size() > 1) {
        return Optional.of(new FieldPath(chain.subList(0, chain.size() - 1)));
    } else {//  w  w w.  jav a2  s .c  o  m
        return Optional.empty();
    }
}

From source file:de.metas.ui.web.window.datatypes.json.filters.JSONDocumentFilterParam.java

/**
 * Creates {@link JSONDocumentFilterParam} from {@link DocumentFilterParam} if the given filter is not internal.
 * /*  ww  w.j  a  v  a  2 s.  c  om*/
 * @param filterParam
 * @return JSON document filter parameter
 */
/* package */static final Optional<JSONDocumentFilterParam> of(final DocumentFilterParam filterParam) {
    // Don't convert internal filters
    if (filterParam.isSqlFilter()) {
        // throw new IllegalArgumentException("Sql filters are not allowed to be converted to JSON filters: " + filterParam);
        return Optional.empty();
    }

    final String fieldName = filterParam.getFieldName();
    final Object jsonValue = Values.valueToJsonObject(filterParam.getValue());
    final Object jsonValueTo = Values.valueToJsonObject(filterParam.getValueTo());
    final JSONDocumentFilterParam jsonFilterParam = new JSONDocumentFilterParam(fieldName, jsonValue,
            jsonValueTo);
    return Optional.of(jsonFilterParam);
}

From source file:org.lendingclub.mercator.aws.SubnetScanner.java

@Override
public Optional<String> computeArn(JsonNode n) {

    String region = n.get(AWSScanner.AWS_REGION_ATTRIBUTE).asText();

    return Optional.of(String.format("arn:aws:ec2:%s:%s:subnet/%s", region,
            n.get(AccountScanner.ACCOUNT_ATTRIBUTE).asText(), n.get("aws_subnetId").asText()));

}

From source file:com.tesobe.obp.transport.json.DecoderNov2016.java

@Override
public Optional<Request> request(String requestId, String request) {
    return Optional.of(new RequestDecoder(requestId, request));
}

From source file:org.lendingclub.mercator.aws.SecurityGroupScanner.java

@Override
public Optional<String> computeArn(JsonNode n) {

    // arn:aws:ec2:region:account-id:security-group/security-group-id
    return Optional.of(String.format("arn:aws:ec2:%s:%s:security-group/%s", n.get("aws_region").asText(),
            n.get("aws_account").asText(), n.get("aws_groupId").asText()));

}

From source file:org.openlmis.fulfillment.util.Merger.java

private static <E> Optional<Merger<E>> of(List<E> elements) {
    if (CollectionUtils.isEmpty(elements)) {
        return Optional.of(new EmptyMerger<>());
    }//from  w w w.ja  v a2 s.co m

    if (elements.size() == 1) {
        return Optional.of(new SingleMerger<>(elements));
    }

    return Optional.empty();
}

From source file:com.devicehive.dao.rdbms.IdentityProviderDaoRdbmsImpl.java

@Override
public IdentityProviderVO getByName(@NotNull String name) {
    IdentityProvider identityProvider = createNamedQuery(IdentityProvider.class, "IdentityProvider.getByName",
            Optional.of(CacheConfig.refresh())).setParameter("name", name).getResultList().stream().findFirst()
                    .orElse(null);/*w  ww . j  a va  2  s .  co  m*/
    return IdentityProvider.convertToVO(identityProvider);
}

From source file:com.orange.ngsi2.model.AttributeTest.java

@Test
public void serializationAttributeWithNullMetadataTest() throws JsonProcessingException {
    Attribute attribute = new Attribute(23.5);
    attribute.setType(Optional.of("float"));
    String json = Utils.objectMapper.writeValueAsString(attribute);
    assertTrue(json.contains("value"));
    assertTrue(json.contains("type"));
    assertTrue(json.contains("metadata"));
}

From source file:io.helixservice.feature.configuration.locator.AbstractResourceLocator.java

/**
 * {@inheritDoc}//  ww  w. ja  va  2 s.  c  om
 */
@Override
public Optional<String> getString(String resourcePath) {
    Optional<String> result = Optional.empty();

    try {
        InputStream in = getStream(resourcePath).get();
        result = Optional.of(IOUtils.toString(in));
    } catch (Throwable t) {
        // Possibly expected
    }

    return result;
}

From source file:com.macrossx.wechat.http.WechatHttpClient.java

public <T> Optional<T> send(final HttpUriRequest request, Class<T> clazz) {
    String result = this.send(request);
    if (result.isEmpty()) {
        return Optional.empty();
    } else {//from   w  w  w .j  a v a 2s.c o  m
        return Optional.of(new Gson().fromJson(result, clazz));
    }
}