List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.opendaylight.netconf.cli.CommandArgHandlerRegistry.java
private static SchemaContext getRemoteSchema(final Class<?> handlerType, final SchemaContextRegistry schemaContextRegistry) { final Optional<SchemaContext> remoteSchemaContext = schemaContextRegistry.getRemoteSchemaContext(); Preconditions.checkState(remoteSchemaContext.isPresent(), "Remote schema context not acquired yet, cannot get handler %s", handlerType); return remoteSchemaContext.get(); }
From source file:harp.HarpMain.java
private static void run(String[] args) throws Exception { Preconditions.checkArgument(args[0].equals("run")); if (args.length != 3) { System.err.println("Harp 'run' usage:"); System.err.println("java -jar <path to harp jar> run ENVIRONMENT EXECUTABLE"); System.err.println();/*from w ww . j av a2s.com*/ System.err.println("Parameters:"); System.err.println("ENVIRONMENT name of the Harp Environment to use for execution"); System.err.println("EXECUTABLE Harp-path of the Harp executable to execute"); System.exit(1); } Optional<Path> potentialRootHarpFilePath = FileUtil.findUpward("root.harp", Paths.get("").toAbsolutePath()); if (!potentialRootHarpFilePath.isPresent()) { throw new FileNotFoundException("No root.harp file was found in or above the present directory."); } Path rootHarpFilePath = potentialRootHarpFilePath.get(); String environmentName = args[1]; // TODO implement a real naming system for paths. A Harp path like run.harp:executable might be // stupid. String[] executablePathParts = args[2].split(":"); String executablePath = executablePathParts[0]; String executableName = executablePathParts[1]; String rootHarpContents = new String(Files.readAllBytes(rootHarpFilePath), Charsets.UTF_8); RootContext rootContext = RootGroovyRunner.parseRootHarpScript(rootHarpContents); Environment environment = rootContext.getEnvironment(environmentName); ScriptGraph linkedScripts = environment.getLinker().link(executablePath); HarpJob thisJob = new HarpJob(linkedScripts, ImmutableList.of(executableName)); Dispatcher dispatcher = environment.getDispatcher(); dispatcher.dispatch(thisJob); System.out.println("Done executing " + executableName); System.exit(0); }
From source file:org.trimou.handlebars.HelperValidator.java
/** * * @param definition//from w w w .j a v a 2 s .c o m * @param hashSize * @see #checkHash(Class, HelperDefinition, int) */ public static void checkHash(HelperDefinition definition, BasicHelper helper) { // Number of required hash entries checkHash(helper.getClass(), definition, helper.numberOfRequiredHashEntries()); // Log a warning message if an unsupported hash key is found Optional<Set<String>> supportedHashKeys = helper.getSupportedHashKeys(); if (supportedHashKeys.isPresent()) { for (String key : definition.getHash().keySet()) { if (!supportedHashKeys.get().contains(key)) { logger.info("Unsupported hash key detected [key: {}, helper: {}, template: {}, line: {}]", key, helper.getClass().getName(), definition.getTagInfo().getTemplateName(), definition.getTagInfo().getLine()); } } } }
From source file:org.opendaylight.netvirt.natservice.internal.NatEvpnUtil.java
private static VpnInstanceOpDataEntry getVpnInstanceOpData(DataBroker broker, String rd) { InstanceIdentifier<VpnInstanceOpDataEntry> id = NatUtil.getVpnInstanceOpDataIdentifier(rd); Optional<VpnInstanceOpDataEntry> vpnInstanceOpData = NatUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id);/*from ww w . jav a2s . c om*/ if (vpnInstanceOpData.isPresent()) { return vpnInstanceOpData.get(); } return null; }
From source file:google.registry.request.RequestParameters.java
/** * Returns first request parameter associated with {@code name} parsed as an optional * {@link InetAddress} (which might be IPv6). * * @throws BadRequestException if request parameter named {@code name} is present but could not * be parsed as an {@link InetAddress} *//* w ww . j av a 2 s. co m*/ public static Optional<InetAddress> extractOptionalInetAddressParameter(HttpServletRequest req, String name) { Optional<String> paramVal = extractOptionalParameter(req, name); if (!paramVal.isPresent()) { return Optional.absent(); } try { return Optional.of(InetAddresses.forString(paramVal.get())); } catch (IllegalArgumentException e) { throw new BadRequestException("Not an IPv4 or IPv6 address: " + name); } }
From source file:org.opendaylight.vpnservice.interfacemgr.renderer.ovs.utilities.VlanTrunkSouthboundUtils.java
private static void addTrunkTerminationPoint(InstanceIdentifier<?> bridgeIid, OvsdbBridgeAugmentation bridgeNode, String bridgeName, String parentInterface, int vlanId, DataBroker dataBroker, WriteTransaction t) { if (vlanId == 0) { LOG.error("Found vlanid 0 for bridge: {}, interface: {}", bridgeName, parentInterface); return;/*from w w w . j av a2 s. c o m*/ } InstanceIdentifier<TerminationPoint> tpIid = createTerminationPointInstanceIdentifier( InstanceIdentifier.keyOf(bridgeIid.firstIdentifierOf(Node.class)), parentInterface); OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpAugmentationBuilder.setName(parentInterface); tpAugmentationBuilder.setVlanMode(OvsdbPortInterfaceAttributes.VlanMode.Trunk); OvsdbTerminationPointAugmentation terminationPointAugmentation = null; Optional<TerminationPoint> terminationPointOptional = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, tpIid, dataBroker); if (terminationPointOptional.isPresent()) { TerminationPoint terminationPoint = terminationPointOptional.get(); terminationPointAugmentation = terminationPoint .getAugmentation(OvsdbTerminationPointAugmentation.class); if (terminationPointAugmentation != null) { List<Trunks> trunks = terminationPointAugmentation.getTrunks(); if (trunks == null) { trunks = new ArrayList<>(); } trunks.add(new TrunksBuilder().setTrunk(new VlanId(vlanId)).build()); tpAugmentationBuilder.setTrunks(trunks); } } else { List<Trunks> trunks = new ArrayList<>(); trunks.add(new TrunksBuilder().setTrunk(new VlanId(vlanId)).build()); tpAugmentationBuilder.setTrunks(trunks); } TerminationPointBuilder tpBuilder = new TerminationPointBuilder(); tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid)); tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build()); t.put(LogicalDatastoreType.CONFIGURATION, tpIid, tpBuilder.build(), true); }
From source file:org.anhonesteffort.flock.crypto.KeyHelper.java
public static boolean masterPassphraseIsValid(Context context) throws GeneralSecurityException, IOException { Optional<String> masterPassphrase = KeyStore.getMasterPassphrase(context); if (!masterPassphrase.isPresent()) return false; Optional<String> encryptedKeyMaterial = KeyStore.getEncryptedKeyMaterial(context); if (!encryptedKeyMaterial.isPresent()) throw new GeneralSecurityException("Where did my key material go! XXX!!!!"); Optional<byte[]> salt = KeyStore.getKeyMaterialSalt(context); if (!salt.isPresent()) throw new GeneralSecurityException("Where did my salt go! XXX!!!!"); SecretKey[] masterKeys = KeyUtil.getCipherAndMacKeysForPassphrase(salt.get(), masterPassphrase.get()); SecretKey masterCipherKey = masterKeys[0]; SecretKey masterMacKey = masterKeys[1]; MasterCipher masterCipher = new MasterCipher(masterCipherKey, masterMacKey); try {/*from ww w .j av a 2s .c om*/ masterCipher.decodeAndDecrypt(encryptedKeyMaterial.get()); } catch (InvalidMacException e) { return false; } return true; }
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 a v a 2 s . 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.edgexfoundry.EdgeXConfigWatcherApplication.java
public static String getNotificationPath(Consul consul) { KeyValueClient kvClient = consul.keyValueClient(); Optional<String> notificationPathOptional = kvClient.getValueAsString(CONSUL_KEY_SEPARATOR + globalPrefix + CONSUL_KEY_SEPARATOR + servicePrefix + CONSUL_KEY_SEPARATOR + notificationPathKey); String notificationPath = ""; if (notificationPathOptional.isPresent()) { notificationPath = notificationPathOptional.get(); } else {//from w ww . ja v a 2 s . c om LOGGER.info("This service doesn't have the notification endpoint"); System.exit(0); } return notificationPath; }
From source file:org.eclipse.buildship.core.workspace.internal.ProjectNameUpdater.java
private static boolean isScheduledForRenaming(IProject duplicate, Set<OmniEclipseProject> allProjects) { if (!duplicate.isOpen()) { return false; }/* w ww . j a v a2 s . co m*/ Optional<OmniEclipseProject> duplicateEclipseProject = Iterables.tryFind(allProjects, Predicates.eclipseProjectMatchesProjectDir(duplicate.getLocation().toFile())); if (!duplicateEclipseProject.isPresent()) { return false; } String newName = checkProjectName(duplicateEclipseProject.get()); return !newName.equals(duplicate.getName()); }