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

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

Introduction

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

Prototype

public static <T> Optional<T> absent() 

Source Link

Document

Returns an Optional instance with no contained reference.

Usage

From source file:org.sfs.util.ExceptionHelper.java

public static <T extends Throwable> Optional<T> unwrapCause(Class<T> exception, Throwable t) {
    int counter = 0;
    Throwable result = t;/* w  w w . j a v  a 2  s  .c o  m*/
    while (result != null && !exception.isAssignableFrom(result.getClass())) {
        if (result.getCause() == null) {
            return Optional.absent();
        }
        if (result.getCause() == result) {
            return Optional.absent();
        }
        if (counter++ > 10) {
            LOGGER.warn("Exception cause unwrapping ran for 10 levels...", t);
            return Optional.absent();
        }
        result = result.getCause();
    }
    if (exception.isAssignableFrom(result.getClass())) {
        return Optional.of((T) result);
    } else {
        return Optional.absent();
    }
}

From source file:org.locationtech.geogig.di.PluginDefaults.java

public PluginDefaults() {
    refs = objects = graph = Optional.absent();
}

From source file:com.arpnetworking.clusteraggregator.AggDataUnifier.java

/**
 * Unifies <code>AggregatedData</code> units.
 * @param aggData List of <code>AggregatedData</code> to unify.
 * @return A new {@code List<AggregatedData>} with unified units.
 */// w  ww.j av a2 s  .c  o  m
public static List<AggregatedData> unify(final Collection<AggregatedData> aggData) {
    Optional<Unit> smallestUnit = Optional.absent();
    for (final AggregatedData data : aggData) {
        smallestUnit = getSmaller(smallestUnit, data.getValue().getUnit());

        for (final Quantity quantity : data.getSamples()) {
            smallestUnit = getSmaller(smallestUnit, quantity.getUnit());
        }
    }

    return FluentIterable.from(aggData).transform(new ConvertUnitTransform(smallestUnit)).toList();
}

From source file:de.keyle.mypet.npc.util.UpdateCheck.java

public static Optional<String> checkForUpdate() {
    try {/*from  w  ww. j a v a  2  s  .  c  o  m*/
        String parameter = "";
        parameter += "build=" + MyPetNpcVersion.getBuild();

        // no data will be saved on the server
        String content = Util.readUrlContent("http://update.mypet-plugin.de/MyPet-NPC?" + parameter);
        JSONParser parser = new JSONParser();
        JSONObject result = (JSONObject) parser.parse(content);

        if (result.containsKey("latest")) {
            return Optional.of(result.get("latest").toString());
        }
    } catch (Exception ignored) {
    }
    return Optional.absent();
}

From source file:org.apache.beam.sdk.extensions.sql.impl.utils.SqlTypeUtils.java

/**
 * Finds an operand with provided type. Returns Optional.absent() if no operand found with
 * matching type//  ww w  . java 2 s .c o  m
 */
public static Optional<BeamSqlExpression> findExpressionOfType(List<BeamSqlExpression> operands,
        SqlTypeName type) {

    for (BeamSqlExpression operand : operands) {
        if (type.equals(operand.getOutputType())) {
            return Optional.of(operand);
        }
    }

    return Optional.absent();
}

From source file:org.opendaylight.openflowplugin.applications.topology.manager.TopologyManagerUtil.java

static void removeAffectedLinks(final NodeId id, final ReadWriteTransaction transaction,
        InstanceIdentifier<Topology> topology) {
    Optional<Topology> topologyOptional = Optional.absent();
    try {//from   w  w w  . ja  v  a2s.  c  o  m
        topologyOptional = transaction.read(LogicalDatastoreType.OPERATIONAL, topology).checkedGet();
    } catch (ReadFailedException e) {
        LOG.warn("Error reading topology data for topology {}: {}", topology, e.getMessage());
        LOG.debug("Error reading topology data for topology.. ", e);
    }
    if (topologyOptional.isPresent()) {
        removeAffectedLinks(id, topologyOptional, transaction, topology);
    }
}

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 {/*  w  ww . j  av a 2 s.  co  m*/
        return Optional.absent();
    }
}

From source file:org.deephacks.confit.spi.CacheManager.java

/**
 * Lookup the most suitable CacheManager available.
 *
 * @return CacheManager.//from  w w w.  ja  va2 s.co  m
 */
public static Optional<CacheManager> lookup() {
    CacheManager manager = lookup.lookup(CacheManager.class);
    if (manager != null) {
        return Optional.of(manager);
    } else {
        return Optional.absent();
    }
}

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

public static <T extends Annotation> Optional<T> validatorFromBean(ModelPropertyContext context,
        Class<T> annotationType) {

    Optional<BeanPropertyDefinition> propertyDefinition = context.getBeanPropertyDefinition();
    Optional<T> notNull = Optional.absent();
    if (propertyDefinition.isPresent()) {
        notNull = annotationFrom(propertyDefinition.get().getGetter(), annotationType)
                .or(annotationFrom(propertyDefinition.get().getField(), annotationType));
    }/* w w  w.  ja v  a  2s .c  o m*/
    return notNull;
}

From source file:edu.ksu.cis.santos.mdcf.dml.ast.exp.Exp.java

Exp() {
    this.type = Optional.absent();
}