List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.opendaylight.vpnservice.utilities.InterfaceUtils.java
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS( DataBroker dataBroker, String interfaceName) { InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId = buildStateInterfaceId( interfaceName);/* www.j av a 2 s . co m*/ Optional<Interface> ifStateOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId); if (ifStateOptional.isPresent()) { return ifStateOptional.get(); } return null; }
From source file:org.anhonesteffort.flock.sync.account.AccountStore.java
public static void setCardInformation(Context context, Optional<FlockCardInformation> cardInformation) { if (cardInformation.isPresent()) { getStore(context).edit()/*w w w . j a va 2s .c o m*/ .putString(KEY_CARD_INFORMATION_ACCOUNT_ID, cardInformation.get().getAccountId()) .putString(KEY_CARD_INFORMATION_LAST_FOUR, cardInformation.get().getCardLastFour()) .putString(KEY_CARD_INFORMATION_EXPIRATION, cardInformation.get().getCardExpiration()).apply(); } else { getStore(context).edit().putString(KEY_CARD_INFORMATION_ACCOUNT_ID, null) .putString(KEY_CARD_INFORMATION_LAST_FOUR, null) .putString(KEY_CARD_INFORMATION_EXPIRATION, null).apply(); } }
From source file:org.opendaylight.netconf.console.utils.NetconfConsoleUtils.java
/** * Blocking read transaction/*from w ww . j a v a 2s . c o m*/ * @param store :DatastoreType * @param path :InstanceIdentifier * @param db :An instance of the {@link DataBroker} * @return :data read from path */ public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read( final LogicalDatastoreType store, final InstanceIdentifier<D> path, final DataBroker db) { D result = null; final ReadOnlyTransaction transaction = db.newReadOnlyTransaction(); Optional<D> optionalData; try { optionalData = transaction.read(store, path).checkedGet(); if (optionalData.isPresent()) { result = optionalData.get(); } else { LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], path); } } catch (ReadFailedException e) { LOG.warn("Failed to read {} ", path, e); } transaction.close(); return result; }
From source file:gobblin.compaction.event.CompactionSlaEventHelper.java
private static long getRecordCount(Optional<Job> job) { if (!job.isPresent()) { return -1l; }// w w w . j a va2 s.co m Counters counters = null; try { counters = job.get().getCounters(); } catch (IOException e) { LOG.debug("Failed to get job counters. Record count will not be set. ", e); return -1l; } Counter recordCounter = counters.findCounter(AvroKeyDedupReducer.EVENT_COUNTER.RECORD_COUNT); if (recordCounter != null && recordCounter.getValue() != 0) { return recordCounter.getValue(); } recordCounter = counters.findCounter(AvroKeyMapper.EVENT_COUNTER.RECORD_COUNT); if (recordCounter != null && recordCounter.getValue() != 0) { return recordCounter.getValue(); } LOG.debug("Non zero record count not found in both mapper and reducer counters"); return -1l; }
From source file:com.google.devtools.build.lib.bazel.repository.downloader.HttpConnection.java
/** * Attempts to detect the encoding the HTTP reponse is using. * * <p>This attempts to read the Content-Encoding header, then the Content-Type header, * then just falls back to UTF-8.</p> * * @throws IOException If something goes wrong (the encoding isn't parsable or is, but isn't * supported by the system)./*from ww w . jav a 2 s . c o m*/ */ @VisibleForTesting static Charset getEncoding(HttpURLConnection connection) throws IOException { String encoding = connection.getContentEncoding(); if (encoding != null) { if (Charset.availableCharsets().containsKey(encoding)) { try { return Charset.forName(encoding); } catch (IllegalArgumentException | UnsupportedOperationException e) { throw new IOException("Got invalid encoding from " + connection.getURL() + ": " + encoding); } } else { throw new IOException("Got unavailable encoding from " + connection.getURL() + ": " + encoding); } } encoding = connection.getContentType(); if (encoding == null) { return StandardCharsets.UTF_8; } try { MediaType mediaType = MediaType.parse(encoding); if (mediaType == null) { return StandardCharsets.UTF_8; } Optional<Charset> charset = mediaType.charset(); if (charset.isPresent()) { return charset.get(); } } catch (IllegalArgumentException | IllegalStateException e) { throw new IOException("Got invalid encoding from " + connection.getURL() + ": " + encoding); } return StandardCharsets.UTF_8; }
From source file:org.opendaylight.netconf.mdsal.connector.MdsalNetconfOperationServiceFactory.java
static Set<Capability> transformCapabilities(final SchemaContext currentContext, final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProviderDependency) { final Set<Capability> capabilities = new HashSet<>(); // Added by netconf-impl by default // capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0")); final Set<Module> modules = currentContext.getModules(); for (final Module module : modules) { Optional<YangModuleCapability> cap = moduleToCapability(module, rootSchemaSourceProviderDependency); if (cap.isPresent()) { capabilities.add(cap.get()); }//from www . ja va 2 s.c om for (final Module submodule : module.getSubmodules()) { cap = moduleToCapability(submodule, rootSchemaSourceProviderDependency); if (cap.isPresent()) { capabilities.add(cap.get()); } } } return capabilities; }
From source file:org.eclipse.buildship.core.workspace.internal.GradleClasspathContainerRuntimeClasspathEntryResolver.java
private static void collectContainerRuntimeClasspath(IClasspathContainer container, List<IRuntimeClasspathEntry> result, boolean includeExportedEntriesOnly) throws CoreException { for (final IClasspathEntry cpe : container.getClasspathEntries()) { if (!includeExportedEntriesOnly || cpe.isExported()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { result.add(JavaRuntime.newArchiveRuntimeClasspathEntry(cpe.getPath())); } else if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) { Optional<IProject> candidate = findAccessibleJavaProject(cpe.getPath().segment(0)); if (candidate.isPresent()) { IJavaProject dependencyProject = JavaCore.create(candidate.get()); IRuntimeClasspathEntry projectRuntimeEntry = JavaRuntime .newProjectRuntimeClasspathEntry(dependencyProject); Collections.addAll(result, JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeEntry, dependencyProject)); collectContainerRuntimeClasspathIfPresent(dependencyProject, result, true); }//from ww w .j a va2 s.c om } } } }
From source file:org.apache.gobblin.data.management.copy.recovery.RecoveryHelper.java
private static String computeGuid(State state, CopyEntity file) throws IOException { Optional<Guid> stateGuid = CopySource.getWorkUnitGuid(state); if (stateGuid.isPresent()) { return Guid.combine(file.guid(), stateGuid.get()).toString(); }/*ww w .j a v a2 s . com*/ throw new IOException("State does not contain a guid."); }
From source file:com.complexible.common.collect.Iterators2.java
public static <T> Iterator<T> present(final Iterator<Optional<T>> theIter) { return new AbstractIterator<T>() { @Override//from w ww. ja va 2 s .c o m protected T computeNext() { while (theIter.hasNext()) { Optional<T> aOptional = theIter.next(); if (aOptional.isPresent()) { return aOptional.get(); } } return endOfData(); } }; }
From source file:org.opendaylight.netconf.notifications.impl.ops.CreateSubscription.java
private static StreamNameType parseStreamIfPresent(final XmlElement operationElement) throws DocumentedException { final Optional<XmlElement> stream = operationElement .getOnlyChildElementWithSameNamespaceOptionally("stream"); return stream.isPresent() ? new StreamNameType(stream.get().getTextContent()) : NetconfNotificationManager.BASE_STREAM_NAME; }