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:ch.css.workingdiary.service.CompetenceAreaService.java

public Optional<List<CompetenceArea>> getCompetenceAreas(final long id) {
    final List<CompetenceArea> competenceAreas = competenceAreaDao.getCompetenceAreas(id);
    return Optional.fromNullable(competenceAreas);
}

From source file:com.spotify.heroic.metric.MetricGroup.java

@JsonCreator
public MetricGroup(@JsonProperty("timestamp") long timestamp,
        @JsonProperty("groups") List<MetricCollection> groups) {
    this.timestamp = timestamp;
    this.groups = Optional.fromNullable(groups).or(EMPTY_GROUPS);
}

From source file:org.jclouds.openstack.trove.v1.domain.Flavor.java

@ConstructorProperties({ "id", "name", "ram", "links" })
protected Flavor(int id, String name, int ram, List<Link> links) {
    this.id = id;
    this.name = Optional.fromNullable(name);
    this.ram = ram;
    this.links = links;
}

From source file:org.locationtech.geogig.model.impl.RevFeatureImpl.java

@Override
public ImmutableList<Optional<Object>> getValues() {
    return ImmutableList.copyOf(Lists.transform(values, (v) -> Optional.fromNullable(safeCopy(v))));
}

From source file:br.com.objectos.wiki.core.page.WikiPageCacheGuice.java

@Override
public Optional<WikiPage> byWikiPageKey(WikiPageKey pageKey) {
    try {// w  ww.ja v  a 2 s .  com
        WikiPage page = pageKeyCache.getUnchecked(pageKey);
        return Optional.fromNullable(page);
    } catch (InvalidCacheLoadException e) {
        return Optional.absent();
    }
}

From source file:org.sonar.server.computation.scm.ScmInfoRepositoryRule.java

@Override
public Optional<ScmInfo> getScmInfo(Component component) {
    checkNotNull(component, "Component cannot be bull");
    ScmInfo scmInfo = scmInfoByFileRef.get(component.getReportAttributes().getRef());
    return Optional.fromNullable(scmInfo);
}

From source file:gobblin.metrics.InnerCounter.java

public InnerCounter(MetricContext context, String name, ContextAwareCounter counter) {
    this.tagged = new Tagged();
    this.name = name;

    Optional<MetricContext> parentContext = context.getParent();
    if (parentContext.isPresent()) {
        this.parentCounter = Optional.fromNullable(parentContext.get().contextAwareCounter(name));
    } else {//from w w  w  .j a  va 2  s .  c  o  m
        this.parentCounter = Optional.absent();
    }

    this.contextAwareCounter = new WeakReference<>(counter);
}

From source file:org.auraframework.impl.css.flavor.FlavorOverrideLocationImpl.java

@Override
public Optional<String> getCondition() {
    return Optional.fromNullable(condition);
}

From source file:com.android.builder.core.DefaultManifestParser.java

@Nullable
@Override/*from w w w. j  av a 2 s . c om*/
public synchronized String getPackage(@NonNull File manifestFile) {
    if (mPackage == null) {
        mPackage = Optional.fromNullable(getStringValue(manifestFile, "/manifest/@package"));
    }
    return mPackage.orNull();
}

From source file:org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl.java

@Override
public Optional<DOMMountPoint> getMountPoint(final YangInstanceIdentifier path) {
    return Optional.fromNullable(mountPoints.get(path));
}