List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider.java
private static Optional<String> getSchemaFromRpc(final RemoteDeviceId id, final NormalizedNode<?, ?> result) { if (result == null) { return Optional.absent(); }//from www. j a v a 2 s . c o m final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> child = ((ContainerNode) result) .getChild(NETCONF_DATA_PATHARG); Preconditions.checkState(child.isPresent() && child.get() instanceof AnyXmlNode, "%s Unexpected response to get-schema, expected response with one child %s, but was %s", id, NETCONF_DATA, result); final DOMSource wrappedNode = ((AnyXmlNode) child.get()).getValue(); Preconditions.checkNotNull(wrappedNode.getNode()); final Element dataNode = (Element) wrappedNode.getNode(); return Optional.of(dataNode.getTextContent().trim()); }
From source file:org.onos.yangtools.yang.data.api.schema.tree.StoreTreeNodes.java
public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final YangInstanceIdentifier path) { T current = tree;//from w w w . j a v a 2s.c om int i = 1; for (PathArgument pathArg : path.getPathArguments()) { Optional<T> potential = current.getChild(pathArg); if (!potential.isPresent()) { throw new IllegalArgumentException(String.format("Child %s is not present in tree.", Iterables.toString(Iterables.limit(path.getPathArguments(), i)))); } current = potential.get(); ++i; } return current; }
From source file:org.deephacks.confit.internal.jpa.JpaBean.java
private static EntityManager getEmOrFail() { Optional<EntityManager> em = getEm(); if (!em.isPresent()) { throw JpaEvents.JPA202_MISSING_THREAD_EM(); }/* w w w . j a v a2 s .c o m*/ return em.get(); }
From source file:org.jboss.aerogear.controller.util.ParameterExtractor.java
private static Consumer getConsumer(final RouteContext routeContext, final Map<String, Consumer> consumers, final Parameter<?> parameter) { final Set<String> mediaTypes = routeContext.getRoute().consumes(); final Optional<String> contentType = extractContentType(routeContext); if (contentType.isPresent()) { final Consumer consumer = consumers.get(contentType.get()); if (consumer != null) { return consumer; }//from w w w.ja v a 2 s .c o m } else { for (String mediaType : mediaTypes) { final Consumer consumer = consumers.get(mediaType); if (consumer != null) { return consumer; } } } throw ExceptionBundle.MESSAGES.noConsumerForMediaType(parameter, consumers.values(), mediaTypes); }
From source file:org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil.java
private static <T extends DataObject> T getDataObject(final ReadTransaction readOnlyTransaction, final InstanceIdentifier<T> identifier) { Optional<T> optionalData = null; try {//from w w w . ja va2s . c om optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get(); if (optionalData.isPresent()) { return optionalData.get(); } } catch (ExecutionException | InterruptedException e) { LOG.error("Read transaction for identifier {} failed.", identifier, e); } return null; }
From source file:org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil.java
public static List<AfiSafi> toAfiSafis(final List<BgpTableType> advertizedTables, final BiFunction<AfiSafi, BgpTableType, AfiSafi> function) { final List<AfiSafi> afiSafis = new ArrayList<>(advertizedTables.size()); for (final BgpTableType tableType : advertizedTables) { final Optional<AfiSafi> afiSafiMaybe = toAfiSafi( new BgpTableTypeImpl(tableType.getAfi(), tableType.getSafi())); if (afiSafiMaybe.isPresent()) { final AfiSafi afiSafi = function.apply(afiSafiMaybe.get(), tableType); afiSafis.add(afiSafi);//from www. j av a 2s .co m } } return afiSafis; }
From source file:org.eclipse.recommenders.utils.rcp.CompilerBindings.java
/** * TODO nested anonymous types are not resolved correctly. JDT uses line numbers for inner types instead of $1,..,$n */// w w w.j a v a 2 s .co m public static Optional<ITypeName> toTypeName(@Nullable TypeBinding binding) { // XXX generics fail if (binding == null) { return absent(); } // final boolean boundParameterizedType = binding.isBoundParameterizedType(); final boolean parameterizedType = binding.isParameterizedType(); // if (binding.isBoundParameterizedType()) { // return null; // } if (binding.isArrayType()) { final int dimensions = binding.dimensions(); final TypeBinding leafComponentType = binding.leafComponentType(); final String arrayDimensions = StringUtils.repeat("[", dimensions); final Optional<ITypeName> typeName = toTypeName(leafComponentType); if (!typeName.isPresent()) { return absent(); } final ITypeName res = VmTypeName.get(arrayDimensions + typeName.get().getIdentifier()); return fromNullable(res); } // TODO: handling of generics is bogus! if (binding instanceof TypeVariableBinding) { final TypeVariableBinding generic = (TypeVariableBinding) binding; if (generic.declaringElement instanceof TypeBinding) { // XXX: for this? binding = (TypeBinding) generic.declaringElement; } else if (generic.superclass != null) { // example Tuple<T1 extends List, T2 extends Number) --> for // generic.superclass (T2)=Number // we replace the generic by its superclass binding = generic.superclass; } } String signature = String.valueOf(binding.genericTypeSignature()); // if (binding instanceof BinaryTypeBinding) { // signature = StringUtils.substringBeforeLast(signature, ";"); // } if (signature.length() == 1) { // no handling needed. primitives always look the same. } else if (signature.endsWith(";")) { signature = StringUtils.substringBeforeLast(signature, ";"); } else { signature = "L" + SignatureUtil.stripSignatureToFQN(signature); } final ITypeName res = VmTypeName.get(signature); return fromNullable(res); }
From source file:org.opendaylight.messenger.impl.MessengerMdsalUtils.java
/** * Executes read as a blocking transaction. * * @param store {@link LogicalDatastoreType} to read * @param path {@link InstanceIdentifier} for path to read * @param <D> the data object type * @return the result as the data object requested *//*from w w w .j a va 2 s . co m*/ public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(final DataBroker dataBroker, final LogicalDatastoreType store, final InstanceIdentifier<D> path) { D result = null; final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction(); Optional<D> optionalDataObject; final CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path); try { optionalDataObject = future.checkedGet(); if (optionalDataObject.isPresent()) { result = optionalDataObject.get(); } else { LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], path); } } catch (final ReadFailedException e) { LOG.warn("Failed to read {} ", path, e); } transaction.close(); return result; }