Example usage for com.google.common.base Optional fromNullable

List of usage examples for com.google.common.base Optional fromNullable

Introduction

In this page you can find the example usage for com.google.common.base Optional fromNullable.

Prototype

public static <T> Optional<T> fromNullable(@Nullable T nullableReference) 

Source Link

Document

If nullableReference is non-null, returns an Optional instance containing that reference; otherwise returns Optional#absent .

Usage

From source file:info.archinnov.achilles.type.Options.java

public Optional<Long> getTimestamp() {
    return Optional.fromNullable(timestamp);
}

From source file:org.opendaylight.yangtools.yang.data.operations.DataOperations.java

public static Optional<MapNode> modify(ListSchemaNode schema, MapNode stored, MapNode modified,
        ModifyAction defaultOperation) throws DataModificationException {

    OperationStack operations = new OperationStack(defaultOperation);

    return new MapNodeModification().modify(schema, Optional.fromNullable(stored),
            Optional.fromNullable(modified), operations);
}

From source file:retrofit.converter.guava.OptionalConverter.java

@Override
public Optional<T> convert(ResponseBody value) throws IOException {
    return Optional.fromNullable(delegate.convert(value));
}

From source file:org.eclipse.recommenders.utils.rcp.RCPUtils.java

public static <T> Optional<T> first(final ISelection s) {
    final T element = unsafeFirstElement(s);
    return Optional.fromNullable(element);
}

From source file:com.dangdang.ddframe.rdb.sharding.parser.visitor.basic.mysql.MySQLDeleteVisitor.java

@Override
public boolean visit(final MySqlDeleteStatement x) {
    getParseContext().setCurrentTable(x.getTableName().toString(), Optional.fromNullable(x.getAlias()));
    return super.visit(x);
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MaterializedContainerNode.java

@Override
public Optional<TreeNode> getChild(final PathArgument childId) {
    return Optional.fromNullable(getModifiedChild(childId));
}

From source file:controllers.HelloAnnotatedController.java

@Timed("hello.annotated")
@GET("/")/*from   w  w w  . j av  a 2 s .c om*/
@Consumes({ Consumes.HTML })
public void hello(String name) {
    getResponse().bind("greeting", "Hello " + Optional.fromNullable(name).or("World")).render("hello");
}

From source file:org.apache.rya.indexing.pcj.fluo.app.export.ParametersBase.java

protected static boolean getBoolean(final Map<String, String> params, final String paramName,
        final boolean defaultValue) {
    checkNotNull(params);//from   w ww  .j a  v a2s . c om
    checkNotNull(paramName);

    final Optional<String> paramValue = Optional.fromNullable(params.get(paramName));
    return paramValue.isPresent() ? Boolean.parseBoolean(paramValue.get()) : defaultValue;
}

From source file:org.jclouds.aws.filters.FormSignerUtils.java

private static Optional<String> getAnnotatedApiVersion(Invocation invocation) {
    final Invokable<?, ?> invokable = invocation.getInvokable();
    if (invokable.isAnnotationPresent(ApiVersionOverride.class)) {
        return Optional.fromNullable(invokable.getAnnotation(ApiVersionOverride.class).value());
    } else {//  w  w  w . j a v  a 2s  .  com
        final Class<?> owner = invokable.getOwnerType().getRawType();
        if (owner.isAnnotationPresent(ApiVersionOverride.class)) {
            return Optional.fromNullable(owner.getAnnotation(ApiVersionOverride.class).value());
        }
    }
    return Optional.absent();
}

From source file:com.github.kevints.mesos.scheduler.server.LibprocessServletUtils.java

static Optional<PID> getSenderPid(HttpServletRequest req) {
    Optional<String> libprocessFrom = Optional.fromNullable(req.getHeader("X-Libprocess-From"));
    if (libprocessFrom.isPresent()) {
        try {//ww w .j a  va  2  s  . co  m
            return Optional.of(PID.fromString(libprocessFrom.get()));
        } catch (IllegalArgumentException e) {
            return Optional.absent();
        }
    }

    Optional<String> userAgent = Optional.fromNullable(req.getHeader("User-Agent"));
    if (userAgent.isPresent()) {
        List<String> pid = Splitter.on("libprocess/").omitEmptyStrings().splitToList(userAgent.get());
        if (pid.size() != 1) {
            return Optional.absent();
        } else {
            try {
                return Optional.of(PID.fromString(pid.get(0)));
            } catch (IllegalArgumentException e) {
                return Optional.absent();
            }
        }
    }

    return Optional.absent();
}