List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:io.mesosphere.mesos.frameworks.cassandra.framework.Main.java
static String frameworkName(final Optional<String> clusterName) { if (clusterName.isPresent()) { return "cassandra." + clusterName.get(); } else {/*from www .j a v a2 s.c o m*/ return "cassandra"; } }
From source file:org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil.java
public static Optional<HwvtepGlobalAugmentation> getManagingNode(DataBroker db, HwvtepGlobalRef ref) { try {//from www . j a v a 2 s .c o m ReadOnlyTransaction transaction = db.newReadOnlyTransaction(); @SuppressWarnings("unchecked") // Note: erasure makes this safe in combination with the typecheck // below InstanceIdentifier<Node> path = (InstanceIdentifier<Node>) ref.getValue(); CheckedFuture<Optional<Node>, ReadFailedException> nf = transaction .read(LogicalDatastoreType.OPERATIONAL, path); transaction.close(); Optional<Node> optional = nf.get(); if (optional != null && optional.isPresent()) { HwvtepGlobalAugmentation hwvtepNode = null; Node node = optional.get(); if (node instanceof HwvtepGlobalAugmentation) { hwvtepNode = (HwvtepGlobalAugmentation) node; } else if (node != null) { hwvtepNode = node.getAugmentation(HwvtepGlobalAugmentation.class); } if (hwvtepNode != null) { return Optional.of(hwvtepNode); } else { LOG.warn("Hwvtep switch claims to be managed by {} but " + "that HwvtepNode does not exist", ref.getValue()); return Optional.absent(); } } else { LOG.warn("Mysteriously got back a thing which is *not* a topology Node: {}", optional); return Optional.absent(); } } catch (Exception e) { LOG.warn("Failed to get HwvtepNode {}", ref, e); return Optional.absent(); } }
From source file:extrabiomes.helpers.BiomeHelper.java
@SuppressWarnings("deprecation") public static void addWeightedGrassGen(Optional<? extends BiomeGenBase> biome, WorldGenerator grassGen, int weight) { if (!biome.isPresent()) return;/* ww w . j a v a 2 s . co m*/ extrabiomes.api.BiomeManager.addWeightedGrassGenForBiome(biome.get(), grassGen, weight); }
From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNodes.java
public static <T extends StoreTreeNode<T>> Entry<YangInstanceIdentifier, T> findClosestsOrFirstMatch( final T tree, final YangInstanceIdentifier path, final Predicate<T> predicate) { Optional<T> parent = Optional.of(tree); Optional<T> current = Optional.of(tree); int nesting = 0; Iterator<PathArgument> pathIter = path.getPathArguments().iterator(); while (current.isPresent() && pathIter.hasNext() && !predicate.apply(current.get())) { parent = current;/*from w w w . j a v a 2 s .c o m*/ current = current.get().getChild(pathIter.next()); nesting++; } if (current.isPresent()) { final YangInstanceIdentifier currentPath = path.getAncestor(nesting); return new SimpleImmutableEntry<>(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 verify state just to be on the safe side. */ Verify.verify(nesting > 0); return new SimpleImmutableEntry<>(path.getAncestor(nesting - 1), parent.get()); }
From source file:org.opendaylight.service.impl.activate.driver.ActivateNetconfConnetion.java
public static void readBierConfigFromAllNetconfNodes() { Topology topology = null;// w w w . jav a2s . c o 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.automagic.deps.doctor.Utils.java
public static Optional<Node> getPluginComment(String parent, Artifact artifact, Document document) { Optional<Node> dependencyNode = getDependencyNode(artifact, document, parent); if (!dependencyNode.isPresent()) { return Optional.absent(); }//from w ww . j a v a2 s.com if (dependencyNode.get().hasChildNodes()) { NodeList childNodes = dependencyNode.get().getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (Node.COMMENT_NODE == node.getNodeType() && contains(node.getNodeValue(), PomWriter.AUTO_COMMENT)) { return Optional.of(node); } } } return Optional.absent(); }
From source file:net.es.nsi.pce.pf.PfUtils.java
public static ServiceDomainType getServiceDomainOrFail(NsiTopology topology, StpType stp) { Optional<ResourceRefType> serviceDomain = Optional.fromNullable(stp.getServiceDomain()); if (serviceDomain.isPresent()) { Optional<ServiceDomainType> sd = Optional .fromNullable(topology.getServiceDomain(stp.getServiceDomain().getId())); if (sd.isPresent()) { return sd.get(); }/*from ww w . j av a2 s . c o m*/ } throw Exceptions.noPathFound("Missing ServiceDomain for source sdpId=" + stp.getId()); }
From source file:org.icgc.dcc.release.job.join.task.CreateSgvObservation.java
public static Optional<Collection<ObjectNode>> convertConsequences( Optional<? extends Iterable<SgvConsequence>> consequences) { if (!consequences.isPresent()) { return Optional.absent(); }//from w w w. ja va 2s . c om val builder = ImmutableList.<ObjectNode>builder(); for (val consequence : consequences.get()) { val json = (ObjectNode) JacksonFactory.MAPPER.valueToTree(consequence); builder.add(trimConsequence(json)); } return Optional.of(builder.build()); }
From source file:org.opendaylight.controller.config.yangjmxgenerator.plugin.CodeWriter.java
private static List<File> persistGeneratedObjects(final File targetBaseDir, final File mainBaseDir, final Map<GeneratedObject, Boolean> gos) throws IOException { List<File> generatedFiles = new ArrayList<>(); for (Entry<GeneratedObject, Boolean> entry : gos.entrySet()) { boolean overwrite = entry.getValue(); File dst;// w w w. j ava2 s . c om if (overwrite) { dst = targetBaseDir; } else { dst = mainBaseDir; } Optional<Entry<FullyQualifiedName, File>> maybePersistEntry = entry.getKey().persist(dst, overwrite); if (maybePersistEntry.isPresent()) { generatedFiles.add(maybePersistEntry.get().getValue()); } } return generatedFiles; }
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 {//from w w w . j a va2 s . co m throw new ExpectedDataObjectNotFoundException(datastoreType, path); } } }