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:com.eucalyptus.util.async.AsyncExceptions.java

/**
 * Test if the given throwable was caused by a web service error with the specified code.
 *
 * @param throwable The possibly wer service caused throwable.
 * @param code The error code to test for
 * @return True if the throwable was caused by a web service error with the given code
 *//*from   w  w w  .  j ava 2  s. c om*/
public static boolean isWebServiceErrorCode(final Throwable throwable, final String code) {
    boolean codeMatch = false;
    final Optional<AsyncWebServiceError> serviceErrorOption = AsyncExceptions.asWebServiceError(throwable);
    if (serviceErrorOption.isPresent()) {
        codeMatch = code.equals(serviceErrorOption.get().getCode());
    }
    return codeMatch;
}

From source file:ch.ge.ve.offlineadmin.controller.matchers.AdditionalTableViewMatchers.java

@Factory
public static <T> Matcher<Node> hasTableCell(final Matcher<T> contentsMatcher) {
    return new TypeSafeMatcher<Node>(TableView.class) {
        @Override//from w  ww. j  av  a2  s.com
        protected boolean matchesSafely(Node item) {
            NodeFinder nodeFinder = FxAssert.assertContext().getNodeFinder();
            NodeQuery nodeQuery = nodeFinder.from(item);

            Optional<Node> result = nodeQuery.lookup(".table-cell").match(cellWithValue(contentsMatcher))
                    .tryQuery();
            return result.isPresent();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(TableView.class.getSimpleName()).appendText(" containing ")
                    .appendDescriptionOf(contentsMatcher);
        }

        @Override
        protected void describeMismatchSafely(Node item, Description mismatchDescription) {
            mismatchDescription.appendText("was ").appendValue(item);
        }
    };
}

From source file:de.azapps.mirakel.helper.MirakelModelPreferences.java

@NonNull
public static AccountMirakel getDefaultAccount() {
    final long id = settings.getLong("defaultAccountID", AccountMirakel.getLocal().getId());
    final Optional<AccountMirakel> a = AccountMirakel.get(id);
    if (a.isPresent()) {
        return a.get();
    }/*w ww  .j a  v  a  2 s.  c  om*/
    return AccountMirakel.getLocal();
}

From source file:org.opendaylight.genius.utils.clustering.ClusteringUtils.java

public static Boolean isEntityOwner(EntityOwnershipService entityOwnershipService, Entity entity,
        long sleepBetweenRetries, int retries) {
    while (retries-- > 0) {
        Optional<EntityOwnershipState> entityState = entityOwnershipService.getOwnershipState(entity);
        if (entityState.isPresent()) {
            EntityOwnershipState entityOwnershipState = entityState.get();
            if (entityOwnershipState.hasOwner()) {
                return entityOwnershipState.isOwner();
            }//from   w w w .  j  av  a2 s.  c om
        }
        LOG.trace("EntityOwnershipState for entity type {} is not yet available. {} retries left",
                entity.getType(), retries);
        try {
            Thread.sleep(sleepBetweenRetries);
        } catch (InterruptedException e) {
            break;
        }
    }
    return false;
}

From source file:org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils.java

public static Optional<DataSchemaNode> findFirstSchema(final QName qname,
        final Iterable<DataSchemaNode> dataSchemaNode) {
    if (dataSchemaNode != null && qname != null) {
        for (DataSchemaNode dsn : dataSchemaNode) {
            if (qname.isEqualWithoutRevision(dsn.getQName())) {
                return Optional.of(dsn);
            } else if (dsn instanceof ChoiceSchemaNode) {
                for (ChoiceCaseNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) {
                    Optional<DataSchemaNode> foundDsn = findFirstSchema(qname, choiceCase.getChildNodes());
                    if (foundDsn != null && foundDsn.isPresent()) {
                        return foundDsn;
                    }/*from  w  w w .  j  a  v a  2s  .  c o  m*/
                }
            }
        }
    }
    return Optional.absent();
}

From source file:org.onos.yangtools.yang.data.api.schema.tree.StoreTreeNodes.java

/**
 * Finds a node in tree//from  w  w w.j ava2  s . co m
 *
 * @param tree Data Tree
 * @param path Path to the node
 * @return Optional with node if the node is present in tree, {@link Optional#absent()} otherwise.
 */
public static <T extends StoreTreeNode<T>> Optional<T> findNode(final T tree,
        final YangInstanceIdentifier path) {
    Optional<T> current = Optional.<T>of(tree);
    Iterator<PathArgument> pathIter = path.getPathArguments().iterator();
    while (current.isPresent() && pathIter.hasNext()) {
        current = current.get().getChild(pathIter.next());
    }
    return current;
}

From source file:org.sonar.server.computation.measure.MeasureDtoToMeasure.java

private static Measure.NewMeasureBuilder setCommonProperties(Measure.NewMeasureBuilder builder,
        MeasureDto measureDto) {/* w  w  w. ja va2 s .  co m*/
    if (measureDto.getAlertStatus() != null) {
        Optional<Measure.Level> qualityGateStatus = toLevel(measureDto.getAlertStatus());
        if (qualityGateStatus.isPresent()) {
            builder.setQualityGateStatus(
                    new QualityGateStatus(qualityGateStatus.get(), measureDto.getAlertText()));
        }
    }
    if (hasAnyVariation(measureDto)) {
        builder.setVariations(createVariations(measureDto));
    }
    Integer ruleId = measureDto.getRuleId();
    if (ruleId != null) {
        builder.forRule(ruleId);
    }
    return builder;
}

From source file:com.google.errorprone.bugpatterns.CheckReturnValue.java

private static Optional<Boolean> checkEnclosingClasses(MethodSymbol method, VisitorState state) {
    Symbol enclosingClass = enclosingClass(method);
    while (enclosingClass instanceof ClassSymbol) {
        Optional<Boolean> result = shouldCheckReturnValue(enclosingClass, state);
        if (result.isPresent()) {
            return result;
        }/*from   w w  w.j a  v a 2  s. c o  m*/
        enclosingClass = enclosingClass.owner;
    }
    return Optional.absent();
}

From source file:org.opendaylight.controller.xml.codec.XmlDocumentUtils.java

public static final Optional<DataSchemaNode> findFirstSchema(final QName qname,
        final Collection<DataSchemaNode> dataSchemaNode) {
    if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
        for (final DataSchemaNode dsn : dataSchemaNode) {
            if (qname.isEqualWithoutRevision(dsn.getQName())) {
                return Optional.<DataSchemaNode>of(dsn);
            } else if (dsn instanceof ChoiceSchemaNode) {
                for (final ChoiceCaseNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) {
                    final Optional<DataSchemaNode> foundDsn = findFirstSchema(qname,
                            choiceCase.getChildNodes());
                    if (foundDsn != null && foundDsn.isPresent()) {
                        return foundDsn;
                    }/*from  w  w w  . jav a 2  s.  com*/
                }
            }
        }
    }
    return Optional.absent();
}

From source file:org.opendaylight.netvirt.natservice.ha.WeightedCentralizedSwitchScheduler.java

public static NaptSwitches getNaptSwitches(DataBroker dataBroker) {
    InstanceIdentifier<NaptSwitches> id = InstanceIdentifier.builder(NaptSwitches.class).build();
    Optional<NaptSwitches> naptSwitches = NatUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    return naptSwitches.isPresent() ? naptSwitches.get() : null;
}