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.geogig.osm.internal.log.ReadOSMMapping.java

@Override
protected Optional<Mapping> _call() {
    Preconditions.checkNotNull(entry);//from w  w w .  j a  va2  s  .c  o m
    BlobStore blobStore = context().blobStore();
    final String pathPrefix = "osm/map/";
    final String path = pathPrefix + entry.getPostMappingId();
    Optional<String> blob = Blobs.getBlobAsString(blobStore, path);
    Mapping mapping = null;
    if (blob.isPresent()) {
        mapping = Mapping.fromString(blob.get());
    }
    return Optional.fromNullable(mapping);
}

From source file:eu.bittrade.libs.steemj.plugins.apis.block.models.GetBlockReturn.java

/**
 * @return the header
 */
public Optional<ExtendedSignedBlock> getBlock() {
    return Optional.fromNullable(block);
}

From source file:org.gerryai.planning.model.ConstantDefinition.java

/**
 * Constructor.//from w  ww.  j av  a2  s  .  c o  m
 * @param name the constant's name.
 * @param type the constant's type.
 */
public ConstantDefinition(final String name, final Type type) {
    this.name = name;
    this.type = Optional.fromNullable(type);
}

From source file:me.lazerka.gae.jersey.oauth2.facebook.FacebookUserPrincipal.java

public Optional<FacebookUser> getFacebookUser() {
    return Optional.fromNullable(facebookUser);
}

From source file:com.vmware.photon.controller.apife.db.dao.BaseDiskDao.java

public Optional<T> findByName(String name, ProjectEntity parent) {
    T result = uniqueResult(/*from ww w .  j  a  va 2  s  .c om*/
            namedQuery(findByName).setString("name", name).setString("projectId", parent.getId()));
    return Optional.fromNullable(result);
}

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

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

From source file:com.aegiswallet.widgets.AegisTypeface.java

public static Optional<Typeface> createTypeface(TextView widget, Optional<Font> option) {
    if (widget.isInEditMode()) {
        return Optional.absent();
    }/* www. j av a 2  s . c  om*/
    synchronized (TYPEFACES) {
        Font font = option.or(Font.regular);
        Typeface typeface = TYPEFACES.get(font);
        if (typeface == null) {
            typeface = Typeface.createFromAsset(widget.getContext().getAssets(), getAssetPath(font));
            TYPEFACES.put(font, typeface);
        }
        // This is never null at runtime, but roboelectric cannot create typefaces so it is null during tests
        return Optional.fromNullable(typeface);
    }
}

From source file:org.sonar.server.computation.qualityprofile.ActiveRulesHolderImpl.java

@Override
public Optional<ActiveRule> get(RuleKey ruleKey) {
    checkState(activeRulesByKey != null, "Active rules have not been initialized yet");
    return Optional.fromNullable(activeRulesByKey.get(ruleKey));
}

From source file:org.apache.provisionr.api.util.WithOptions.java

public String getOptionOr(String key, String value) {
    return Optional.fromNullable(getOption(key)).or(value);
}

From source file:org.opendaylight.yangtools.yang.parser.repo.RevisionDependencyResolver.java

@Override
protected boolean isKnown(final Collection<SourceIdentifier> haystack, final ModuleImport mi) {
    final String rev = mi.getRevision() != null ? QName.formattedRevision(mi.getRevision()) : null;
    final SourceIdentifier msi = SourceIdentifier.create(mi.getModuleName(), Optional.fromNullable(rev));

    // Quick lookup
    if (haystack.contains(msi)) {
        return true;
    }/*ww w.j a  v a2 s . c  o m*/

    // Slow revision-less walk
    return rev == null && findWildcard(haystack, mi.getModuleName()) != null;
}