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:com.dangdang.ddframe.rdb.sharding.parser.visitor.basic.mysql.MySQLInsertVisitor.java

@Override
public boolean visit(final MySqlInsertStatement x) {
    final String tableName = SQLUtil.getExactlyValue(x.getTableName().toString());
    getParseContext().setCurrentTable(tableName, Optional.fromNullable(x.getAlias()));
    if (null == x.getValues()) {
        return super.visit(x);
    }/*from   w ww  .  j a  v  a  2  s.co m*/
    Collection<String> autoIncrementColumns = getParseContext().getShardingRule()
            .getAutoIncrementColumns(tableName);
    List<SQLExpr> columns = x.getColumns();
    List<SQLExpr> values = x.getValues().getValues();
    for (int i = 0; i < x.getColumns().size(); i++) {
        String columnName = SQLUtil.getExactlyValue(columns.get(i).toString());
        getParseContext().addCondition(columnName, tableName, BinaryOperator.EQUAL, values.get(i),
                getDatabaseType(), getParameters());
        if (autoIncrementColumns.contains(columnName)) {
            autoIncrementColumns.remove(columnName);
        }
    }
    if (autoIncrementColumns.isEmpty()) {
        return super.visit(x);
    }
    supplyAutoIncrementColumn(autoIncrementColumns, tableName, columns, values);
    return super.visit(x);
}

From source file:net.oneandone.troilus.Optionals.java

/**
 * @param obj  the object (could also be an optional)
 * @return the object wrapped by guava optional
 *//*w ww. ja  va2  s.c  om*/
@SuppressWarnings("unchecked")
public static <T> Optional<T> toGuavaOptional(T obj) {
    if (obj == null) {
        return Optional.<T>absent();
    }

    if (isGuavaOptional(obj)) {
        return (Optional<T>) obj;

    } else if (isJavaOptional(obj)) {
        return Optional.fromNullable((T) fromJavaOptional(obj));

    } else {
        return Optional.of(obj);
    }
}

From source file:com.haulmont.cuba.desktop.settings.DesktopSettingsClient.java

@Override
public String getSetting(String name) {
    Map<String, Optional<String>> settings = getCache();
    Optional<String> cached = settings.get(name);
    if (cached != null) {
        return cached.orNull();
    }//from   w ww. j  a v a2  s  .  com

    String setting = userSettingService.loadSetting(ClientType.DESKTOP, name);
    settings.put(name, Optional.fromNullable(setting));

    return setting;
}

From source file:org.geogig.osm.internal.history.Changeset.java

public Optional<String> getComment() {
    return Optional.fromNullable(comment);
}

From source file:org.jclouds.ultradns.ws.binders.ZoneAndResourceRecordToXML.java

@SuppressWarnings("unchecked")
@Override//from w w w .j  a v a 2s .  c om
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
    String zoneName = postParams.get("zoneName").toString();
    ResourceRecord record = ResourceRecord.class.cast(postParams.get("resourceRecord"));
    String xml = toXML(zoneName, record);
    Optional<?> guid = Optional.fromNullable(postParams.get("guid"));
    if (guid.isPresent()) {
        xml = update(guid.get(), xml);
    }
    return (R) request.toBuilder().payload(xml).build();
}

From source file:se.sics.sweep.webservice.toolbox.Result.java

public static Result internalError(String reason) {
    return new Result(Status.INTERNAL_ERROR, Optional.fromNullable(reason));
}

From source file:org.opendaylight.mdsal.dom.spi.SimpleDOMMountPoint.java

@Override
public <T extends DOMService> Optional<T> getService(final Class<T> cls) {
    return Optional.fromNullable(services.getInstance(cls));
}

From source file:org.apache.aurora.scheduler.http.api.security.IniShiroRealmModule.java

public IniShiroRealmModule() {
    this(Optional.fromNullable(SHIRO_INI_PATH.get()));
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.v2.ServerResponse05.java

public Optional<String> getBugId() {
    return Optional.fromNullable(bugId);
}