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:springfox.bean.validators.plugins.BeanValidators.java

@VisibleForTesting
static <T extends Annotation> Optional<T> annotationFrom(AnnotatedMember nullableMember,
        Class<T> annotationType) {

    Optional<AnnotatedMember> member = Optional.fromNullable(nullableMember);
    Optional<T> notNull = Optional.absent();
    if (member.isPresent()) {
        notNull = FluentIterable.from(member.get().annotations()).filter(annotationType).first();
    }//from w  w w  . j a v  a2 s.  c o m
    return notNull;
}

From source file:org.geogit.geotools.data.GeogitTransactionState.java

public Optional<GeogitTransaction> getGeogitTransaction() {
    return Optional.fromNullable(this.geogitTx);
}

From source file:org.jclouds.abiquo.domain.infrastructure.HypervisorType.java

public boolean supportsExtraHardDisks() {
    Optional<String> constraint = Optional.fromNullable(getConstraints().get("extra_hard_disk"));
    return Boolean.parseBoolean(constraint.or("true"));
}

From source file:com.youtube.serializer.YoutubeActivityUtil.java

/**
 * Given a {@link com.google.api.services.youtube.YouTube.Videos} object and an
 * {@link org.apache.streams.pojo.json.Activity} object, fill out the appropriate details
 *
 * @param video/* w w w. ja v  a 2s .  c o m*/
 * @param activity
 * @throws org.apache.streams.exceptions.ActivitySerializerException
 */
public static void updateActivity(Video video, Activity activity, String channelId)
        throws ActivitySerializerException {
    activity.setActor(buildActor(video, video.getSnippet().getChannelId()));
    activity.setVerb("post");

    activity.setId(formatId(activity.getVerb(), Optional.fromNullable(video.getId()).orNull()));

    activity.setPublished(new DateTime(video.getSnippet().getPublishedAt().getValue()));
    activity.setTitle(video.getSnippet().getTitle());
    activity.setContent(video.getSnippet().getDescription());
    activity.setUrl("https://www.youtube.com/watch?v=" + video.getId());

    activity.setProvider(getProvider());

    activity.setObject(buildActivityObject(video));

    addYoutubeExtensions(activity, video);
}

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

public Event(final long timestamp, final Map<String, String> payload) {
    this.timestamp = timestamp;
    this.payload = Optional.fromNullable(payload).or(EMPTY_PAYLOAD);
}

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

/**
 * This method finds the flavor by name and kind.
 *
 * @param name - supplies the name of the flavor
 * @param kind - supplies the kind of the flavor
 * @return - returns and Optional that includes a flavor or .absent() if no flavor by this name and kind
 * exists./*from   www  .  j  ava 2  s.com*/
 */
public Optional<FlavorEntity> findByNameAndKind(String name, String kind) {
    return Optional.fromNullable(uniqueResult(
            namedQuery("Flavor.findByNameAndKind").setString("name", name).setString("kind", kind)));
}

From source file:org.jclouds.googlecomputeengine.compute.loaders.SubnetworkLoader.java

@Override
public Optional<Subnetwork> load(RegionAndName key) throws ExecutionException {
    try {//from   www  .  j a  va 2s . c o m
        return Optional.fromNullable(api.subnetworksInRegion(key.regionId()).get(key.name()));
    } catch (Exception ex) {
        throw new ExecutionException(message(key, ex), ex);
    }
}

From source file:com.facebook.swift.parser.model.ThriftField.java

public ThriftField(String name, ThriftType type, Long identifier, Required required, ConstValue value,
        List<TypeAnnotation> annotations) {
    this.name = checkNotNull(name, "name");
    this.type = checkNotNull(type, "type");
    this.identifier = Optional.fromNullable(identifier);
    this.required = checkNotNull(required, "required");
    this.value = Optional.fromNullable(value);
    this.annotations = checkNotNull(annotations, "annotations");
}

From source file:de.flapdoodle.logparser.stacktrace.AbstractStackFrame.java

public Optional<CauseBy> cause() {
    return Optional.fromNullable(_cause);
}

From source file:com.twitter.aurora.scheduler.storage.mem.MemQuotaStore.java

@Override
public Optional<IQuota> fetchQuota(String role) {
    checkNotNull(role);
    return Optional.fromNullable(quotas.get(role));
}