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.opendaylight.netvirt.vpnmanager.utilities.InterfaceUtils.java

public static String getEndpointIpAddressForDPN(DataBroker broker, BigInteger dpnId) {
    String nextHopIp = null;//from w ww  . j av  a2  s  . c o  m
    InstanceIdentifier<DPNTEPsInfo> tunnelInfoId = InstanceIdentifier.builder(DpnEndpoints.class)
            .child(DPNTEPsInfo.class, new DPNTEPsInfoKey(dpnId)).build();
    Optional<DPNTEPsInfo> tunnelInfo = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, tunnelInfoId);
    if (tunnelInfo.isPresent()) {
        List<TunnelEndPoints> nexthopIpList = tunnelInfo.get().getTunnelEndPoints();
        if (nexthopIpList != null && !nexthopIpList.isEmpty()) {
            nextHopIp = new String(nexthopIpList.get(0).getIpAddress().getValue());
        }
    }
    return nextHopIp;
}

From source file:org.opendaylight.service.impl.activate.driver.ActivateNetconfConnetion.java

public static void readBierConfigFromAllNetconfNodes() {

    Topology topology = null;//  w  ww. java  2  s. co  m
    final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction();
    Optional<Topology> optionalData;
    try {
        optionalData = transaction.read(LogicalDatastoreType.OPERATIONAL, NETCONF_TOPOLOGY_IID).checkedGet();
        if (optionalData.isPresent()) {
            topology = optionalData.get();
        } else {
            LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], NETCONF_TOPOLOGY_IID);
        }
    } catch (ReadFailedException e) {
        LOG.warn("Failed to read {} ", NETCONF_TOPOLOGY_IID, e);
    }
    transaction.close();

    if (topology == null) {
        LOG.info("No netconf nodes in datastore!!");
        return;
    }

    for (final Node node : topology.getNode()) {
        NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
        if ((netconfNode.getConnectionStatus() == NetconfNodeConnectionStatus.ConnectionStatus.Connected)
                && (!node.getNodeId().getValue().equals("controller-config"))) {
            bierConfigReader.readBierGlobal(node.getNodeId().getValue());
            LOG.info("Read bier global of {}", node.getNodeId());

        }

    }

}

From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.CaseShorthandImpl.java

private static ChoiceCaseNode getOriginalIfPresent(final SchemaNode caseShorthandNode) {
    if (caseShorthandNode instanceof DerivableSchemaNode) {
        final Optional<? extends SchemaNode> original = ((DerivableSchemaNode) caseShorthandNode).getOriginal();
        if (original.isPresent()) {
            return new CaseShorthandImpl((DataSchemaNode) original.get());
        }/*w w w.  ja  va  2s .  c  o m*/
    }
    return null;
}

From source file:io.crate.planner.consumer.GlobalAggregateConsumer.java

private static Plan globalAggregates(Functions functions, QueriedTableRelation table, ConsumerContext context,
        RowGranularity projectionGranularity) {
    QuerySpec querySpec = table.querySpec();
    if (querySpec.groupBy().isPresent() || !querySpec.hasAggregates()) {
        return null;
    }/*from   ww w . j a va  2  s  . c  o m*/

    Planner.Context plannerContext = context.plannerContext();
    validateAggregationOutputs(table.tableRelation(), querySpec.outputs());
    // global aggregate: collect and partial aggregate on C and final agg on H

    ProjectionBuilder projectionBuilder = new ProjectionBuilder(functions, querySpec);
    SplitPoints splitPoints = projectionBuilder.getSplitPoints();

    AggregationProjection ap = projectionBuilder.aggregationProjection(splitPoints.leaves(),
            splitPoints.aggregates(), Aggregation.Step.ITER, Aggregation.Step.PARTIAL, projectionGranularity);
    RoutedCollectPhase collectPhase = RoutedCollectPhase.forQueriedTable(plannerContext, table,
            splitPoints.leaves(), ImmutableList.of(ap));
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, ap.outputs().size(), 1, null);

    //// the handler stuff
    List<Projection> mergeProjections = new ArrayList<>();
    mergeProjections
            .add(projectionBuilder.aggregationProjection(splitPoints.aggregates(), splitPoints.aggregates(),
                    Aggregation.Step.PARTIAL, Aggregation.Step.FINAL, RowGranularity.CLUSTER));

    Optional<HavingClause> havingClause = querySpec.having();
    if (havingClause.isPresent()) {
        HavingClause having = havingClause.get();
        mergeProjections.add(ProjectionBuilder.filterProjection(splitPoints.aggregates(), having));
    }
    Limits limits = plannerContext.getLimits(querySpec);
    TopNProjection topNProjection = ProjectionBuilder.topNProjection(splitPoints.aggregates(), null,
            limits.offset(), limits.finalLimit(), querySpec.outputs());
    mergeProjections.add(topNProjection);
    MergePhase mergePhase = new MergePhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(),
            "mergeOnHandler", collectPhase.nodeIds().size(), Collections.emptyList(),
            Symbols.extractTypes(ap.outputs()), mergeProjections, DistributionInfo.DEFAULT_SAME_NODE, null);
    return new Merge(collect, mergePhase, TopN.NO_LIMIT, 0, topNProjection.outputs().size(), 1, null);
}

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

public static <T extends StoreTreeNode<T>> Map.Entry<YangInstanceIdentifier, T> findClosestsOrFirstMatch(
        final T tree, final YangInstanceIdentifier path, final Predicate<T> predicate) {
    Optional<T> parent = Optional.<T>of(tree);
    Optional<T> current = Optional.<T>of(tree);

    int nesting = 0;
    Iterator<PathArgument> pathIter = path.getPathArguments().iterator();
    while (current.isPresent() && pathIter.hasNext() && !predicate.apply(current.get())) {
        parent = current;// w  w  w. j av a  2 s .  c om
        current = current.get().getChild(pathIter.next());
        nesting++;
    }
    if (current.isPresent()) {
        final YangInstanceIdentifier currentPath = YangInstanceIdentifier
                .create(Iterables.limit(path.getPathArguments(), nesting));
        return new SimpleEntry<YangInstanceIdentifier, T>(currentPath, current.get());
    }

    /*
     * Subtracting 1 from nesting level at this point is safe, because we
     * cannot reach here with nesting == 0: that would mean the above check
     * for current.isPresent() failed, which it cannot, as current is always
     * present. At any rate we check state just to be on the safe side.
     */
    Preconditions.checkState(nesting > 0);
    final YangInstanceIdentifier parentPath = YangInstanceIdentifier
            .create(Iterables.limit(path.getPathArguments(), nesting - 1));
    return new SimpleEntry<YangInstanceIdentifier, T>(parentPath, parent.get());
}

From source file:org.sonar.server.computation.task.projectanalysis.component.ComponentRootBuilder.java

private static String createProjectVersion(ScannerReport.Component component, String projectUuid,
        Function<String, Optional<SnapshotDto>> analysisSupplier) {
    String version = trimToNull(component.getVersion());
    if (version != null) {
        return version;
    }/*from  w  w w.ja  va  2 s . c om*/
    Optional<SnapshotDto> snapshotDto = analysisSupplier.apply(projectUuid);
    if (snapshotDto.isPresent()) {
        return MoreObjects.firstNonNull(snapshotDto.get().getVersion(), DEFAULT_PROJECT_VERSION);
    }
    return DEFAULT_PROJECT_VERSION;
}

From source file:org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.java

public static <T extends DataObject> T syncRead(DataBroker broker, LogicalDatastoreType datastoreType,
        InstanceIdentifier<T> path) throws ReadFailedException {

    try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
        Optional<T> optionalDataObject = tx.read(datastoreType, path).checkedGet();
        if (optionalDataObject.isPresent()) {
            return optionalDataObject.get();
        } else {// w ww.j a  v a 2  s.  c  o  m
            throw new ExpectedDataObjectNotFoundException(datastoreType, path);
        }
    }
}

From source file:jcomposition.processor.utils.AnnotationUtils.java

private static Optional<AnnotationValue> getParameterFrom(TypeElement typeElement,
        Class<? extends Annotation> annotationClass, String paramName, ProcessingEnvironment env) {
    Optional<AnnotationMirror> annotationMirror = MoreElements.getAnnotationMirror(typeElement,
            annotationClass);/* w  ww  .j a  v  a  2 s. com*/

    if (annotationMirror.isPresent()) {
        AnnotationValue value = getAnnotationValue(annotationMirror.get(), paramName, env);

        return Optional.fromNullable(value);
    }

    return Optional.absent();
}

From source file:org.opendaylight.netvirt.vpnmanager.utilities.InterfaceUtils.java

public static Optional<String> getMacAddressForInterface(DataBroker dataBroker, String interfaceName) {
    Optional<String> macAddressOptional = Optional.absent();
    InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId = buildStateInterfaceId(
            interfaceName);//from  www.  j  av  a  2  s.c om
    Optional<Interface> ifStateOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId);
    if (ifStateOptional.isPresent()) {
        PhysAddress macAddress = ifStateOptional.get().getPhysAddress();
        if (macAddress != null) {
            macAddressOptional = Optional.of(macAddress.getValue());
        }
    }
    return macAddressOptional;
}

From source file:org.opendaylight.bier.driver.common.util.DataGetter.java

public static MountPoint getMountPoint(String nodeId, ConfigurationResult result,
        MountPointService mountService) {
    if (mountService == null) {
        LOG.error(result.MOUNT_SERVICE_NULL);
        result.setCfgResult(ConfigurationResult.Result.FAILED);
        result.setFailureReason(result.MOUNT_SERVICE_NULL);
        return null;
    }//from w ww .  j a  v  a 2 s.co  m
    Optional<MountPoint> nodeMountPoint = mountService
            .getMountPoint(IidConstants.NETCONF_TOPO_IID.child(Node.class, new NodeKey(new NodeId(nodeId))));

    if (!nodeMountPoint.isPresent()) {
        LOG.error(ConfigurationResult.MOUNT_POINT_FAILUE + nodeId);
        result.setCfgResult(ConfigurationResult.Result.FAILED);
        result.setFailureReason(ConfigurationResult.MOUNT_POINT_FAILUE + nodeId);
        return null;
    }

    result.setCfgResult(ConfigurationResult.Result.SUCCESSFUL);
    return nodeMountPoint.get();

}