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.arpnetworking.configuration.jackson.BaseJsonNodeSource.java

/**
 * Find the <code>JsonNode</code> if one exists from a specified root node
 * given a sequence of keys to look-up./*from  ww  w .j  av a2s .  c o  m*/
 *
 * @param node The root <code>JsonNode</code>.
 * @param keys The sequence of keys to search for.
 * @return The <code>Optional</code> <code>JsonNode</code> instance.
 */
protected static Optional<JsonNode> getValue(final Optional<JsonNode> node, final String... keys) {
    JsonNode jsonNode = node.orNull();
    for (final String key : keys) {
        if (jsonNode == null) {
            break;
        }
        jsonNode = jsonNode.get(key);
    }
    return Optional.fromNullable(jsonNode);
}

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

@JsonCreator
public Average(@JsonProperty("sampling") SamplingQuery sampling) {
    super(Optional.fromNullable(sampling).or(SamplingQuery::empty));
}

From source file:com.facebook.buck.rules.ProjectConfigBuilder.java

public ProjectConfigBuilder setSrcRoots(@Nullable ImmutableList<String> srcRoots) {
    arg.srcRoots = Optional.fromNullable(srcRoots);
    return this;
}

From source file:org.zalando.github.spring.pagination.LinkRelationExtractor.java

public Optional<LinkRelation> extractLinkRelation(String linkHeaderValue, String relation) {
    Iterable<String> splittedHeaderIterable = splitter.split(linkHeaderValue);
    Iterable<LinkRelation> linkRelations = Iterables.transform(splittedHeaderIterable, transformer);
    linkRelations = Iterables.filter(linkRelations, new RelationsPredicate(relation));
    return Optional.fromNullable(Iterables.getFirst(linkRelations, null));
}

From source file:de.uniulm.omi.cloudiator.sword.core.domain.builders.LoginCredentialBuilder.java

public LoginCredential build() {
    return new LoginCredentialImpl(this.username, Optional.fromNullable(this.privateKey),
            Optional.fromNullable(this.password));
}

From source file:org.gerryai.planning.model.logic.Variable.java

/**
 * Constructor./*w  w  w.j a  v a2 s  . c o  m*/
 * @param name the name of the variable
 * @param type the type of the variable
 */
public Variable(final String name, final Type type) {
    this.name = name;
    this.type = Optional.fromNullable(type);
}

From source file:org.gerryai.planning.parser.pddl.internal.logic.SymbolStash.java

/**
 * Push a symbol name into the stash.//w  w  w  .  j a v  a2 s  .  c o  m
 * @param name the name of the symbol being built.
 */
public void push(final String name) {
    checkState(!symbol.isPresent(), "Cannot push a symbol if the last one hasn't been collected yet");
    checkNotNull(name);
    symbol = Optional.fromNullable(name);
}

From source file:com.google.devtools.build.lib.rules.cpp.CppModuleMap.java

public CppModuleMap(Artifact artifact, Artifact umbrellaHeader, String name) {
    this.artifact = artifact;
    this.umbrellaHeader = Optional.fromNullable(umbrellaHeader);
    this.name = name;
}

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

@JsonCreator
public CountUnique(@JsonProperty("sampling") SamplingQuery sampling) {
    super(Optional.fromNullable(sampling).or(SamplingQuery::empty));
}

From source file:com.sleepcamel.bsoneer.processor.domain.ElementResolver.java

@Override
public Optional<TypeElement> visitDeclared(DeclaredType t, Void p) {
    TypeElement asElement = (TypeElement) t.asElement();
    if (asElement.getSuperclass().getKind().equals(TypeKind.NONE)) {
        asElement = null;/*from  w  w  w  . ja v a2s  .c o m*/
    }
    return Optional.fromNullable(asElement);
}