List of usage examples for com.google.common.base Optional isPresent
public abstract boolean isPresent();
From source file:org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils.java
public static ForwardingCtx createForwardingContext(TenantId tenantId, L2FloodDomainId l2FdId, ReadTransaction rTx) {//from w ww .java 2 s. co m Optional<L2FloodDomain> potentialL2Fd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IidFactory.l2FloodDomainIid(tenantId, l2FdId), rTx); if (!potentialL2Fd.isPresent()) { return new ForwardingCtx(null, null, null); } L2BridgeDomainId l2BdId = potentialL2Fd.get().getParent(); if (l2BdId == null) { return new ForwardingCtx(potentialL2Fd.get(), null, null); } Optional<L2BridgeDomain> potentialL2Bd = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IidFactory.l2BridgeDomainIid(tenantId, l2BdId), rTx); if (!potentialL2Bd.isPresent()) { return new ForwardingCtx(potentialL2Fd.get(), null, null); } L3ContextId l3ContextId = potentialL2Bd.get().getParent(); if (l3ContextId == null) { return new ForwardingCtx(potentialL2Fd.get(), potentialL2Bd.get(), null); } Optional<L3Context> potentialL3Context = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IidFactory.l3ContextIid(tenantId, l3ContextId), rTx); if (!potentialL3Context.isPresent()) { return new ForwardingCtx(potentialL2Fd.get(), potentialL2Bd.get(), null); } return new ForwardingCtx(potentialL2Fd.get(), potentialL2Bd.get(), potentialL3Context.get()); }
From source file:io.scigraph.services.jersey.MultivaluedMapUtils.java
/*** * Converts a {@link MultivaluedMap} to a {@link Multimap}. * // w w w. ja v a 2 s . com * @param map the original map * @param separator an optional separator to further split the values in the map * @return the new multimap */ public static Multimap<String, Object> multivaluedMapToMultimap(MultivaluedMap<String, String> map, Optional<Character> separator) { Multimap<String, Object> merged = ArrayListMultimap.create(); for (Entry<String, List<String>> entry : map.entrySet()) { for (String value : entry.getValue()) { if (separator.isPresent()) { merged.putAll(entry.getKey(), Splitter.on(separator.get()).split(value)); } else { merged.put(entry.getKey(), value); } } } return merged; }
From source file:net.caseif.voxem.world.Block.java
public static boolean isAir(Optional<Block> block) { return !block.isPresent() || block.get().getType() == Material.AIR; }
From source file:org.pau.assetmanager.business.HistoricalStockValuesBusiness.java
public static Optional<Double> converSymbolToEuro(String symbol, Double value) { Optional<Double> valueInDollars = Optional.absent(); if (symbol.contains(".")) { // check if the market is supported String marketSymbol = symbol.split("\\.")[1]; for (String pattern : HistoricalStocksValuesDownloader.LABEL_TO_CURRENCY_MAP.keySet()) { if (marketSymbol.matches(pattern)) { // supported, we get the change String marketSymbolYahoo = HistoricalStocksValuesDownloader.LABEL_TO_CURRENCY_MAP.get(pattern); Optional<HistoricalStockValue> currencyLastHistoricalValue = getHistoricalLastValueForSymbol( marketSymbolYahoo); if (currencyLastHistoricalValue.isPresent()) { valueInDollars = Optional.of(value / currencyLastHistoricalValue.get().getValue()); }//from w ww . j av a2s .c o m } } } else { // no market, we assume dollars (American market) valueInDollars = Optional.of(value); } if (valueInDollars.isPresent()) { // convert to euros Optional<HistoricalStockValue> currencyLastHistoricalValue = getHistoricalLastValueForSymbol( HistoricalStocksValuesDownloader.EURO); if (currencyLastHistoricalValue.isPresent()) { return Optional.of(valueInDollars.get() * currencyLastHistoricalValue.get().getValue()); } } return Optional.absent(); }
From source file:org.opendaylight.netconf.util.osgi.NetconfConfigUtil.java
/** * @param context from which properties are being read. * @param infixProp either tcp or ssh/*from ww w.j a va2s . c o m*/ * @return value if address and port are present and valid, Optional.absent otherwise. */ public static Optional<InetSocketAddress> extractNetconfServerAddress(final BundleContext context, final InfixProp infixProp) { final Optional<String> address = getProperty(context, getNetconfServerAddressKey(infixProp)); final Optional<String> port = getProperty(context, PREFIX_PROP + infixProp + PORT_SUFFIX_PROP); if (address.isPresent() && port.isPresent()) { try { return Optional.of(parseAddress(address, port)); } catch (final IllegalArgumentException | SecurityException e) { LOG.warn("Unable to parse {} netconf address from {}:{}, fallback to default", infixProp, address, port, e); } } return Optional.absent(); }
From source file:org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.java
/** * @param context from which properties are being read. * @param infixProp either tcp or ssh/* w w w . jav a 2 s . c o m*/ * @return value if address and port are present and valid, Optional.absent otherwise. * @throws IllegalStateException if address or port are invalid, or configuration is missing */ public static Optional<InetSocketAddress> extractNetconfServerAddress(final BundleContext context, final InfixProp infixProp) { final Optional<String> address = getProperty(context, getNetconfServerAddressKey(infixProp)); final Optional<String> port = getProperty(context, PREFIX_PROP + infixProp + PORT_SUFFIX_PROP); if (address.isPresent() && port.isPresent()) { try { return Optional.of(parseAddress(address, port)); } catch (final RuntimeException e) { LOG.warn("Unable to parse {} netconf address from {}:{}, fallback to default", infixProp, address, port, e); } } return Optional.absent(); }
From source file:alluxio.cli.validation.Utils.java
/** * Checks whether a path is the mounting point of a RAM disk volume. * * @param path a string represents the path to be checked * @param fsTypes an array of strings represents expected file system type * @return true if the path is the mounting point of volume with one of the given fsTypes, * false otherwise// www . j a v a2s. c o m * @throws IOException if the function fails to get the mount information of the system */ public static boolean isMountingPoint(String path, String[] fsTypes) throws IOException { List<UnixMountInfo> infoList = ShellUtils.getUnixMountInfo(); for (UnixMountInfo info : infoList) { Optional<String> mountPoint = info.getMountPoint(); Optional<String> fsType = info.getFsType(); if (mountPoint.isPresent() && mountPoint.get().equals(path) && fsType.isPresent()) { for (String expectedType : fsTypes) { if (fsType.get().equalsIgnoreCase(expectedType)) { return true; } } } } return false; }
From source file:de.azapps.mirakel.settings.model_settings.special_list.dialogfragments.editfragments.ConjunctionFragment.java
private static SpecialListsConjunctionList getRootProperty( @NonNull final Optional<SpecialListsBaseProperty> where, @NonNull final List<Integer> backStack) { if (where.isPresent()) { if (where.get() instanceof SpecialListsConjunctionList) { SpecialListsConjunctionList currentProperty = (SpecialListsConjunctionList) where.get(); for (int i = 0; i < backStack.size(); i++) { if (backStack.get(i) == NEW_PROPERTY) { final SpecialListsConjunctionList newList = new SpecialListsConjunctionList( (currentProperty.getConjunction() == SpecialListsConjunctionList.CONJUNCTION.AND) ? SpecialListsConjunctionList.CONJUNCTION.OR : SpecialListsConjunctionList.CONJUNCTION.AND, new ArrayList<SpecialListsBaseProperty>()); backStack.set(i, currentProperty.getChilds().size()); currentProperty.getChilds().add(newList); return newList; }//from w ww . j a v a 2 s . c om if (currentProperty.getChilds().get(backStack.get(i)) instanceof SpecialListsConjunctionList) { currentProperty = (SpecialListsConjunctionList) currentProperty.getChilds() .get(backStack.get(i)); } else { final List<SpecialListsBaseProperty> childs = new ArrayList<>(1); childs.add(currentProperty.getChilds().get(backStack.get(i))); currentProperty = new SpecialListsConjunctionList( (currentProperty.getConjunction() == SpecialListsConjunctionList.CONJUNCTION.AND) ? SpecialListsConjunctionList.CONJUNCTION.OR : SpecialListsConjunctionList.CONJUNCTION.AND, childs); break; } } return currentProperty; } } return new SpecialListsConjunctionList(SpecialListsConjunctionList.CONJUNCTION.AND, new ArrayList<SpecialListsBaseProperty>(0)); }
From source file:org.opendaylight.vpnservice.itm.confighelpers.ItmInternalTunnelDeleteWorker.java
private static boolean checkIfTrunkExists(BigInteger srcDpnId, BigInteger dstDpnId, Class<? extends TunnelTypeBase> tunType, DataBroker dataBroker) { boolean existsFlag = false; InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(TunnelList.class) .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId, tunType)); Optional<InternalTunnel> internalTunnels = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);//from w w w. j av a 2 s . c om if (internalTunnels.isPresent()) existsFlag = true; return existsFlag; }
From source file:org.icgc.dcc.release.job.join.task.ObservationJoinTask.java
private static Function<Tuple2<String, SsmPrimaryFeatureType>, Boolean> filterControlledRecords() { return t -> { SsmPrimaryFeatureType row = t._2; Optional<Marking> marking = Marking.from(row.getMarking()); checkState(marking.isPresent(), "Failed to resolve marking from %s", row); return !marking.get().isControlled(); };//w w w . j a va 2s .c o m }