Example usage for com.google.common.base Optional isPresent

List of usage examples for com.google.common.base Optional isPresent

Introduction

In this page you can find the example usage for com.google.common.base Optional isPresent.

Prototype

public abstract boolean isPresent();

Source Link

Document

Returns true if this holder contains a (non-null) instance.

Usage

From source file:ph.devcon.android.category.db.Category.java

public static Category toCategory(CategoryAPI categoryAPI) {
    Category category = null;/* ww w  .  j a  v a 2s  .c  o m*/
    Optional<CategoryAPI> categoryAPIOptional = Optional.fromNullable(categoryAPI);
    if (categoryAPIOptional.isPresent()) {
        String categoryName = categoryAPIOptional.get().getName();
        if (!Util.isNullOrEmpty(categoryName)) {
            category = new Category();
            category.setName(categoryAPIOptional.get().getName());
        }
    }
    return category;
}

From source file:com.github.jsdossier.jscomp.Types.java

private static boolean hasTypeExpression(Optional<JSDocInfo.Marker> marker) {
    return marker.isPresent() && marker.get().getType() != null;
}

From source file:org.sonar.server.computation.task.projectanalysis.step.BuildComponentTreeStep.java

@CheckForNull
private static Analysis toAnalysis(Optional<SnapshotDto> snapshotDto) {
    if (snapshotDto.isPresent()) {
        SnapshotDto dto = snapshotDto.get();
        return new Analysis.Builder().setId(dto.getId()).setUuid(dto.getUuid()).setCreatedAt(dto.getCreatedAt())
                .build();/*  w w w. j  a v a  2 s  .  co  m*/
    }
    return null;
}

From source file:org.geogit.storage.FieldType.java

public static FieldType forValue(Optional<Object> field) {
    if (field.isPresent()) {
        Object realField = field.get();
        Class<?> fieldClass = realField.getClass();
        return forBinding(fieldClass);
    } else {//w  w  w .j a  v  a 2s.  co m
        return NULL;
    }
}

From source file:com.facebook.buck.util.environment.MacWifiSsidFinder.java

private static Optional<String> getSsidFromInterface(Optional<Proxy> defaultInterface) {
    if (!defaultInterface.isPresent()) {
        LOG.debug("No Wi-Fi interface found.");
        return Optional.absent();
    }/*from  w  w  w.  j a  va2s  .co  m*/
    LOG.debug("Getting SSID from Wi-Fi interface: %s", defaultInterface.get());

    // NSString *ssid = [defaultInterface ssid];
    Object ssid = defaultInterface.get().send("ssid");
    if (ssid == null) {
        LOG.debug("No SSID found for interface %s.", defaultInterface.get());
        return Optional.absent();
    }
    if (!(ssid instanceof String)) {
        LOG.error("Fetched SSID, but got unexpected non-string type (got: %s).", ssid);
        return Optional.absent();
    }

    String ssidString = (String) ssid;
    LOG.debug("Found SSID: %s", ssidString);
    return Optional.of(ssidString);
}

From source file:org.mayocat.image.ImageDataLoader.java

private static <T> Predicate<Optional<T>> present() {
    return new Predicate<Optional<T>>() {
        public boolean apply(Optional<T> optional) {
            return optional.isPresent();
        }/*ww w  .j  a  v a  2  s .c om*/
    };
}

From source file:springfox.documentation.spring.web.readers.operation.ModelRefs.java

public static Optional<ModelRef> modelRef(Optional<ResolvedType> type, ModelContext modelContext,
        TypeNameExtractor nameExtractor) {
    if (!type.isPresent()) {
        return Optional.absent();
    }/*  w ww .j a v  a 2 s  . c om*/
    return Optional.of(modelRef(type.get(), modelContext, nameExtractor));
}

From source file:springfox.bean.validators.plugins.RangeAnnotations.java

public static AllowableRangeValues allowableRange(Optional<Min> min, Optional<Max> max) {
    AllowableRangeValues myvalues = null;

    if (min.isPresent() && max.isPresent()) {
        LOG.debug("@Min+@Max detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(Double.toString(min.get().value()), false,
                Double.toString(max.get().value()), false);

    } else if (min.isPresent()) {
        LOG.debug("@Min detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(Double.toString(min.get().value()), false, null, null);

    } else if (max.isPresent()) {
        LOG.debug("@Max detected: adding AllowableRangeValues to field ");
        myvalues = new AllowableRangeValues(null, null, Double.toString(max.get().value()), false);
    }//from  w w w. jav  a 2  s  .  c o  m
    return myvalues;
}

From source file:org.eclipse.recommenders.codesearch.rcp.index.indexer.BindingHelper.java

public static Optional<String> getIdentifier(final ITypeBinding b) {
    if (b == null) {
        return absent();
    }// ww  w  .  j  av  a2 s  . c  o  m
    final Optional<ITypeName> opt = BindingUtils.toTypeName(b);
    if (!opt.isPresent()) {
        return absent();
    }
    return of(opt.get().getIdentifier());
}

From source file:gobblin.commit.DeliverySemantics.java

/**
 * Get the devliery semantics type from {@link ConfigurationKeys#DELIVERY_SEMANTICS}.
 * The default value is {@link Type#AT_LEAST_ONCE}.
 *//* www .  j  a va  2s  .c om*/
public static DeliverySemantics parse(State state) {
    String value = state.getProp(ConfigurationKeys.GOBBLIN_RUNTIME_DELIVERY_SEMANTICS, AT_LEAST_ONCE.toString())
            .toUpperCase();
    Optional<DeliverySemantics> semantics = Enums.getIfPresent(DeliverySemantics.class, value);
    Preconditions.checkState(semantics.isPresent(), value + " is not a valid delivery semantics");
    return semantics.get();
}