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:org.apache.mailet.base.MailetPipelineLogging.java

private static Optional<Logger> getLogger(Mailet mailet) {
    MailetConfig mailetConfig = mailet.getMailetConfig();
    if (mailetConfig == null) {
        return Optional.absent();
    }//from   ww w.  jav  a2 s .co m
    MailetContext mailetContext = mailetConfig.getMailetContext();
    if (mailetContext == null) {
        return Optional.absent();
    }
    return Optional.fromNullable(mailetContext.getLogger());
}

From source file:com.haulmont.cuba.web.settings.WebSettingsClient.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();
    }/* w w w . j  a  v a2 s  .  c om*/

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

    return setting;
}

From source file:org.apache.cassandra.cql.hooks.ExecutionContext.java

public ExecutionContext(ThriftClientState clientState, String queryString, List<ByteBuffer> variables) {
    this.clientState = clientState;
    this.queryString = Optional.fromNullable(queryString);
    this.variables = variables;
}

From source file:org.mayocat.shop.cart.CartBuilder.java

public CartBuilder setShipping(PriceWithTaxes shipping) {
    this.shipping = Optional.fromNullable(shipping);
    return this;
}

From source file:com.spotify.heroic.aggregation.simple.Quantile.java

@JsonCreator
public Quantile(@JsonProperty("sampling") SamplingQuery sampling, @JsonProperty("q") Double q,
        @JsonProperty("error") Double error) {
    super(Optional.fromNullable(sampling).or(SamplingQuery::empty));
    this.q = Optional.fromNullable(q).or(DEFAULT_QUANTILE);
    this.error = Optional.fromNullable(error).or(DEFAULT_ERROR);
}

From source file:com.blackberry.bdp.kontroller.resources.AuthenticationStatusResource.java

@GET
@Timed/*w  w  w  . j a  v  a2s .c o m*/
@Produces(value = MediaType.APPLICATION_JSON)
public AuthenticationStatus get(@Auth(required = false) User user) throws Exception {
    AuthenticationStatus status = new AuthenticationStatus();
    if (Optional.fromNullable(user).isPresent()) {
        status.setAuthenticated(true);
        status.setUser(user);
    }
    return status;
}

From source file:com.datastax.driver.core.schemabuilder.Drop.java

Drop(String keyspaceName, String itemName, DroppedItem itemType) {
    this.itemType = itemType.name();
    validateNotEmpty(keyspaceName, "Keyspace name");
    validateNotEmpty(itemName, this.itemType.toLowerCase() + " name");
    validateNotKeyWord(keyspaceName, String
            .format("The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName));
    validateNotKeyWord(itemName, String.format(
            "The " + this.itemType.toLowerCase() + " name '%s' is not allowed because it is a reserved keyword",
            itemName));//w w w .  ja v a2s. c  o  m
    this.itemName = itemName;
    this.keyspaceName = Optional.fromNullable(keyspaceName);
}

From source file:io.crate.sql.tree.Window.java

public Window(List<Expression> partitionBy, List<SortItem> orderBy, WindowFrame frame) {
    this.partitionBy = checkNotNull(partitionBy, "partitionBy is null");
    this.orderBy = checkNotNull(orderBy, "orderBy is null");
    this.frame = Optional.fromNullable(frame);
}

From source file:io.crate.sql.tree.IfExpression.java

public IfExpression(Expression condition, Expression trueValue, Expression falseValue) {
    this.condition = checkNotNull(condition, "condition is null");
    this.trueValue = checkNotNull(trueValue, "trueValue is null");
    this.falseValue = Optional.fromNullable(falseValue);
}

From source file:org.whispersystems.textsecuregcm.storage.PendingDevicesManager.java

public Optional<String> getCodeForNumber(String number) {
    Optional<String> code = memcacheGet(number);

    if (!code.isPresent()) {
        code = Optional.fromNullable(pendingDevices.getCodeForNumber(number));

        if (code.isPresent()) {
            memcacheSet(number, code.get());
        }//w w w.j  a v  a2s .com
    }

    return code;
}