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:org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.java

static double getMeasureVariations(CounterInitializationContext counterContext, String metricKey) {
    Optional<Measure> measure = counterContext.getMeasure(metricKey);
    if (!measure.isPresent() || !measure.get().hasVariation()) {
        return 0d;
    }//from w  w w . j a  va  2 s .c  om
    return measure.get().getVariation();
}

From source file:org.apache.usergrid.persistence.model.entity.EntityMap.java

public static Optional<EntityMap> fromEntity(Optional<Entity> entity) {
    if (entity.isPresent()) {
        EntityMap map = fromEntity(entity.get());
        return Optional.fromNullable(map);
    } else {/*from   w  ww  .  j a  v a 2 s  .co m*/
        return Optional.absent();
    }
}

From source file:org.sonar.server.computation.formula.SumFormula.java

private static <T extends Number> boolean shouldCreateMeasure(CreateMeasureContext context, Optional<T> value) {
    return value.isPresent() && CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType());
}

From source file:de.azapps.tools.OptionalUtils.java

public static <T> void writeToParcel(final @NonNull Parcel dest, final @NonNull Optional<T> value) {
    dest.writeValue(value.isPresent());
    if (value.isPresent()) {
        dest.writeValue(value.get());/* w ww. j a v  a2s.c  om*/
    }
}

From source file:org.onos.yangtools.yang.model.util.SchemaNodeUtils.java

public static final SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
    Optional<SchemaNode> previous = Optional.absent();
    Optional<SchemaNode> next = getOriginalIfPossible(data);
    while (next.isPresent()) {
        previous = next;/*from w w w  .  j a  v  a  2s .com*/
        next = getOriginalIfPossible(next.get());
    }
    return previous.orNull();
}

From source file:org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils.java

public static SchemaNode getRootOriginalIfPossible(final SchemaNode data) {
    Optional<SchemaNode> previous = Optional.absent();
    Optional<SchemaNode> next = getOriginalIfPossible(data);
    while (next.isPresent()) {
        previous = next;//w  w  w.ja v  a 2  s  . c  om
        next = getOriginalIfPossible(next.get());
    }
    return previous.orNull();
}

From source file:org.opendaylight.alto.spce.network.util.DataHelper.java

/**
 * @param dataBroker/*  w ww . j a  v  a2  s. c o  m*/
 * @param iid
 * @param type
 * @param <T>
 * @return The data of iid
 * @throws ReadDataFailedException
 */
public static <T extends DataObject> T readFromDataStore(DataBroker dataBroker, InstanceIdentifier<T> iid,
        LogicalDatastoreType type) throws ReadDataFailedException {
    ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
    Future<Optional<T>> future = tx.read(type, iid);
    try {
        if (future != null) {
            Optional<T> optional = future.get();
            if (optional.isPresent()) {
                return optional.get();
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    } finally {
        tx.close();
    }
    throw new ReadDataFailedException();
}

From source file:google.registry.util.UrlFetchUtils.java

/** Sets the HTTP Basic Authentication header on an {@link HTTPRequest}. */
public static void setAuthorizationHeader(HTTPRequest req, Optional<String> login) {
    if (login.isPresent()) {
        String token = base64().encode(login.get().getBytes(UTF_8));
        req.addHeader(new HTTPHeader(AUTHORIZATION, "Basic " + token));
    }//from   w  w  w .j a v  a  2s .c  o  m
}

From source file:org.apache.distributedlog.namespace.DistributedLogNamespaceImpl.java

private static <T> java.util.Optional<T> gOptional2JOptional(Optional<T> gOptional) {
    if (gOptional.isPresent()) {
        return java.util.Optional.of(gOptional.get());
    } else {/*w  ww  .j  av  a  2s.  c om*/
        return java.util.Optional.empty();
    }
}

From source file:com.treasuredata.client.TDClientException.java

private static final String formatErrorMessage(ErrorType errorType, String message, Optional<Exception> cause) {
    String rootCauseErrorMessage = cause.isPresent() ? " The root cause: " + cause.get().getMessage() : "";
    return String.format("[%s] %s%s", errorType.name(), message != null ? message : "", rootCauseErrorMessage);
}