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:li.klass.fhem.domain.CulHmHeatingMode.java

public static Optional<CulHmHeatingMode> heatingModeFor(String value) {
    if (value.equalsIgnoreCase("MANU")) {
        value = MANUAL.name();// w w w  .  j a  va  2 s  . c  o m
    }
    try {
        return Optional.of(CulHmHeatingMode.valueOf(value.toUpperCase(Locale.getDefault())));
    } catch (Exception e) {
        Log.e(CulHmHeatingMode.class.getName(), "cannot set heating mode from value " + value, e);
        return Optional.absent();
    }
}

From source file:de.flapdoodle.guava.Expectations.java

/**
 * gives one, if only one value exist/*from w w  w .ja  v  a 2  s.co m*/
 * gives none on everything else
 * 
 * @param values
 * @return optional
 */
public static <T> Optional<T> noneOrOneIfOnlyOne(Iterator<T> iterator) {
    Optional<T> ret = intNoneOrOne(iterator);
    if (iterator.hasNext()) {
        return Optional.absent();
    }
    return ret;
}

From source file:org.geogit.api.hooks.Hookables.java

/**
 * Returns the filename to be used for a script corresponding to the hook for a given GeoGit
 * operation. Returns {@link Optional.absent} if the specified operation does not allows hooks
 * //from  w ww  . ja  v a  2  s  .c  o  m
 * @param class the operation
 * @return the string to be used as filename for storing the script files for the corresponding
 *         hook
 */
public static Optional<String> getFilename(Class<? extends AbstractGeoGitOp> clazz) {
    Hookable annotation = clazz.getAnnotation(Hookable.class);
    if (annotation != null) {
        return Optional.of(annotation.name());
    } else {
        return Optional.absent();
    }
}

From source file:com.github.rinde.rinsim.ui.renderers.PointUtil.java

static Optional<Point> intersectionPoint(Point own1, Point own2, Point oth1, Point oth2) {

    final double dx1 = own2.x - own1.x;
    final double dy1 = own2.y - own1.y;
    final double dx2 = oth2.x - oth1.x;
    final double dy2 = oth2.y - oth1.y;

    final double angle1 = Math.PI + Math.atan2(-dy1, -dx1);
    final double angle2 = Math.PI + Math.atan2(-dy2, -dx2);

    final double sin1 = Math.sin(angle1);
    final double sin2 = Math.sin(angle2);
    final double cos1 = Math.cos(angle1);
    final double cos2 = Math.cos(angle2);

    final double d = sin1 * cos2 - sin2 * cos1;
    if (Math.abs(d) < TOLERANCE) {
        return Optional.absent();
    }/*from ww  w  . j a  v  a2 s.  c  o m*/
    final double d1 = Math.hypot(dx1, dy1);
    final double d2 = Math.hypot(dx2, dy2);
    final double offset1 = own2.x * own1.y - own1.x * own2.y / d1;
    final double offset2 = oth2.x * oth1.y - oth1.x * oth2.y / d2;

    return Optional.of(new Point((cos1 * offset2 - cos2 * offset1) / d, (sin1 * offset2 - sin2 * offset1) / d));
}

From source file:com.google.gerrit.server.change.ChangeTriplet.java

/**
 * Parse a triplet out of a string.//from ww w.j  ava2s  . c om
 *
 * @param triplet string of the form "project~branch~id".
 * @return the triplet if the input string has the proper format, or absent if
 *     not.
 */
public static Optional<ChangeTriplet> parse(String triplet) {
    int t2 = triplet.lastIndexOf('~');
    int t1 = triplet.lastIndexOf('~', t2 - 1);
    if (t1 < 0 || t2 < 0) {
        return Optional.absent();
    }

    String project = Url.decode(triplet.substring(0, t1));
    String branch = Url.decode(triplet.substring(t1 + 1, t2));
    String changeId = Url.decode(triplet.substring(t2 + 1));

    ChangeTriplet result = new AutoValue_ChangeTriplet(new Branch.NameKey(new Project.NameKey(project), branch),
            new Change.Key(changeId));
    return Optional.of(result);
}

From source file:org.opendaylight.faas.fabricmgr.FabMgrDatastoreUtil.java

public static <T extends DataObject> Optional<T> readData(final LogicalDatastoreType storeType,
        final InstanceIdentifier<T> path) {
    final ReadTransaction tx = FabMgrDatastoreDependency.getDataProvider().newReadOnlyTransaction();
    CheckedFuture<Optional<T>, ReadFailedException> resultFuture = tx.read(storeType, path);
    try {// w ww  .  ja v  a  2s  .com
        return resultFuture.checkedGet();
    } catch (ReadFailedException e) {
        LOG.error("FABMGR: ERROR: Read failed from DS.", e);
        return Optional.absent();
    }
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.WriteLeafCandidateNode.java

@Override
@Nonnull
public Optional<NormalizedNode<?, ?>> getDataBefore() {
    return Optional.absent();
}

From source file:org.apache.aurora.scheduler.discovery.ZooKeeperConfig.java

/**
 * Creates a new client configuration with defaults for the session timeout and credentials.
 *
 * @param useCurator {@code true} to use Apache Curator; otherwise commons/zookeeper is used.
 * @param servers ZooKeeper server addresses.
 * @return A new configuration.//from w ww .j  av  a 2  s. co m
 */
public static ZooKeeperConfig create(boolean useCurator, Iterable<InetSocketAddress> servers) {
    return new ZooKeeperConfig(useCurator, servers, Optional.absent(), // chrootPath
            false, ZooKeeperUtils.DEFAULT_ZK_SESSION_TIMEOUT, Optional.absent()); // credentials
}

From source file:com.qcadoo.mes.basic.util.StaffNameExtractor.java

private static Optional<String> extract(final Entity staff, final String firstFieldName,
        final String secondFieldName) {
    if (staff == null) {
        return Optional.absent();
    }/*from  w w  w . j av a 2 s  .  co m*/
    String firstFieldValue = staff.getStringField(firstFieldName);
    String secondFieldValue = staff.getStringField(secondFieldName);
    return Optional.of(String.format("%s %s", firstFieldValue, secondFieldValue));
}

From source file:eu.europa.ec.grow.espd.domain.enums.criteria.CriteriaList.java

public static Optional<CcvCriterion> findById(String uuid) {
    if (CRITERIA.get(uuid) != null) {
        return Optional.of(CRITERIA.get(uuid));
    }//from   ww  w . j a v  a2s  .c o m
    return Optional.absent();
}