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:net.es.nsi.pce.pf.PfUtils.java

public static P2PServiceBaseType removeP2PServiceBaseTypeOrFail(AttrConstraints constraints) {
    // Generic reservation information are in string constraint attributes,
    // but the P2PS specific constraints are in the P2PS P2PServiceBaseType.
    Optional<ObjectAttrConstraint> p2pObject = Optional
            .fromNullable(constraints.removeObjectAttrConstraint(Point2PointTypes.P2PS));
    if (p2pObject.isPresent()) {
        return p2pObject.get().getValue(P2PServiceBaseType.class);
    }/*w w w  . j av a2 s  . c  om*/

    throw Exceptions.missingParameter(Point2PointTypes.P2PS, "null", "null");
}

From source file:org.apache.gobblin.cli.JobInfoPrintUtils.java

/**
 * Print information about one specific job.
 * @param jobExecutionInfoOptional Job info to print
 *///  w w w  .  j  a v  a  2s  .  c om
public static void printJob(Optional<JobExecutionInfo> jobExecutionInfoOptional) {
    if (!jobExecutionInfoOptional.isPresent()) {
        System.err.println("Job id not found.");
        return;
    }

    JobExecutionInfo jobExecutionInfo = jobExecutionInfoOptional.get();
    List<List<String>> data = new ArrayList<>();
    List<String> flags = Arrays.asList("", "-");

    data.add(Arrays.asList("Job Name", jobExecutionInfo.getJobName()));
    data.add(Arrays.asList("Job Id", jobExecutionInfo.getJobId()));
    data.add(Arrays.asList("State", jobExecutionInfo.getState().toString()));
    data.add(Arrays.asList("Completed/Launched Tasks",
            String.format("%d/%d", jobExecutionInfo.getCompletedTasks(), jobExecutionInfo.getLaunchedTasks())));
    data.add(Arrays.asList("Start Time", dateTimeFormatter.print(jobExecutionInfo.getStartTime())));
    data.add(Arrays.asList("End Time", dateTimeFormatter.print(jobExecutionInfo.getEndTime())));
    data.add(Arrays.asList("Duration",
            jobExecutionInfo.getState() == JobStateEnum.COMMITTED
                    ? periodFormatter.print(new Period(jobExecutionInfo.getDuration().longValue()))
                    : "-"));
    data.add(Arrays.asList("Tracking URL", jobExecutionInfo.getTrackingUrl()));
    data.add(Arrays.asList("Launcher Type", jobExecutionInfo.getLauncherType().name()));

    new CliTablePrinter.Builder().data(data).flags(flags).delimiterWidth(2).build().printTable();

    JobInfoPrintUtils.printMetrics(jobExecutionInfo.getMetrics());
}

From source file:org.opendaylight.controller.sal.connect.netconf.NetconfMapping.java

static CompositeNode toNotificationNode(NetconfMessage message, Optional<SchemaContext> ctx) {
    if (ctx.isPresent()) {
        SchemaContext schemaContext = ctx.get();
        Set<NotificationDefinition> notifications = schemaContext.getNotifications();
        Document document = message.getDocument();
        return XmlDocumentUtils.notificationToDomNodes(document, Optional.fromNullable(notifications));
    }/*from www  . j a v a  2s .c  om*/
    return null;
}

From source file:org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriParser.java

public static PrefixDescriptors serializePrefixDescriptors(final ContainerNode prefixDesc) {
    final PrefixDescriptorsBuilder prefixDescBuilder = new PrefixDescriptorsBuilder();
    if (prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).isPresent()) {
        prefixDescBuilder.setMultiTopologyId(new TopologyIdentifier(
                (Integer) prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).get().getValue()));
    }/*  ww  w  . ja v  a  2  s.  c  o m*/
    final Optional<DataContainerChild<? extends PathArgument, ?>> ospfRoute = prefixDesc
            .getChild(OSPF_ROUTE_NID);
    if (ospfRoute.isPresent()) {
        prefixDescBuilder.setOspfRouteType(
                OspfRouteType.forValue(domOspfRouteTypeValue((String) ospfRoute.get().getValue())));
    }
    if (prefixDesc.getChild(IP_REACH_NID).isPresent()) {
        final String prefix = (String) prefixDesc.getChild(IP_REACH_NID).get().getValue();

        try {
            Ipv4Util.bytesForPrefixBegin(new Ipv4Prefix(prefix));
            prefixDescBuilder.setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix(prefix)));
        } catch (final IllegalArgumentException e) {
            LOG.debug("Creating Ipv6 prefix because", e);
            prefixDescBuilder.setIpReachabilityInformation(new IpPrefix(new Ipv6Prefix(prefix)));
        }
    }
    return prefixDescBuilder.build();
}

From source file:org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper.java

public static List<Routes> getAllVpnExtraRoutes(DataBroker dataBroker, String vpnName, List<String> usedRds,
        String destPrefix) {/*  w  w  w .  j a v  a2 s  .  c o m*/
    List<Routes> routes = new ArrayList<>();
    for (String rd : usedRds) {
        Optional<Routes> extraRouteInfo = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
                getVpnToExtrarouteVrfIdIdentifier(vpnName, rd, destPrefix));
        if (extraRouteInfo.isPresent()) {
            routes.add(extraRouteInfo.get());
        }
    }
    return routes;
}

From source file:org.anhonesteffort.flock.sync.SyncWorkerUtil.java

protected static List<String> handleFilterUidsMissingLocally(
        AbstractLocalComponentCollection<?> localCollection, Set<String> uids) throws RemoteException {
    List<String> uidsMissingLocally = new LinkedList<String>();

    for (String uid : uids) {
        Optional<Long> localId = localCollection.getLocalIdForUid(uid);
        if (!localId.isPresent())
            uidsMissingLocally.add(uid);
    }/*www  .j  a v  a2s.c  o m*/

    return uidsMissingLocally;
}

From source file:com.facebook.watchman.WatchmanTransportBuilder.java

public static WatchmanTransport discoverTransport(long duration, TimeUnit unit)
        throws WatchmanTransportUnavailableException {
    Optional<Path> optionalExecutable = ExecutableFinder.getOptionalExecutable(Paths.get("watchman"),
            ImmutableMap.copyOf(System.getenv()));
    if (!optionalExecutable.isPresent()) {
        throw new WatchmanTransportUnavailableException();
    }//from w  w w .j  a v  a  2  s . c o m
    return discoverTransport(optionalExecutable.get(), duration, unit);
}

From source file:org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory.java

private static Optional<SSLOptions> getSslOptions() {
    Optional<String> truststorePath = Optional.of(CassandraUtils.getTruststore());
    Optional<String> truststorePassword = Optional.of(CassandraUtils.getTruststorePassword());

    if (truststorePath.isPresent() && truststorePassword.isPresent()) {
        SSLContext context;//  w  ww  .  j a  va  2 s.c o m
        try {
            context = getSslContext(truststorePath.get(), truststorePassword.get());
        } catch (UnrecoverableKeyException | KeyManagementException | NoSuchAlgorithmException
                | KeyStoreException | CertificateException | IOException e0) {
            throw new RuntimeException(e0);
        }
        String[] css = new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA" };
        return Optional.of(new SSLOptions(context, css));
    }
    return Optional.absent();
}

From source file:org.opendaylight.netconf.impl.SubtreeFilter.java

/**
 * Shallow compare src node to filter: tag name and namespace must match.
 * If filter node has no children and has text content, it also must match.
 *///from  www  . ja v  a2  s  . co m
private static MatchingResult matches(XmlElement src, XmlElement filter) throws DocumentedException {
    boolean tagMatch = src.getName().equals(filter.getName())
            && src.getNamespaceOptionally().equals(filter.getNamespaceOptionally());
    MatchingResult result = null;
    if (tagMatch) {
        // match text content
        Optional<String> maybeText = filter.getOnlyTextContentOptionally();
        if (maybeText.isPresent()) {
            if (maybeText.equals(src.getOnlyTextContentOptionally()) || prefixedContentMatches(filter, src)) {
                result = MatchingResult.CONTENT_MATCH;
            } else {
                result = MatchingResult.CONTENT_MISMATCH;
            }
        }
        // match attributes, combination of content and tag is not supported
        if (result == null) {
            for (Attr attr : filter.getAttributes().values()) {
                // ignore namespace declarations
                if (XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI()) == false) {
                    // find attr with matching localName(),  namespaceURI(),  == value() in src
                    String found = src.getAttribute(attr.getLocalName(), attr.getNamespaceURI());
                    if (attr.getValue().equals(found) && result != MatchingResult.NO_MATCH) {
                        result = MatchingResult.TAG_MATCH;
                    } else {
                        result = MatchingResult.NO_MATCH;
                    }
                }
            }
        }
        if (result == null) {
            result = MatchingResult.TAG_MATCH;
        }
    }
    if (result == null) {
        result = MatchingResult.NO_MATCH;
    }
    LOG.debug("Matching {} to {} resulted in {}", src, filter, result);
    return result;
}

From source file:be.nbb.demetra.various.SpreadSheetProviderBuddy2.java

private static DataSet toDataSet(TsMoniker moniker) {
    Optional<IDataSourceProvider> provider = TsProviders.lookup(IDataSourceProvider.class, moniker);
    if (provider.isPresent()) {
        DataSet dataSet = provider.get().toDataSet(moniker);
        if (dataSet != null) {
            return dataSet;
        }// w  w w .j a  va 2  s .c  o m
    }
    return null;
}