List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.opendaylight.netvirt.vpnmanager.utilities.InterfaceUtils.java
public static String getEndpointIpAddressForDPN(DataBroker broker, BigInteger dpnId) { String nextHopIp = null;//from ww w.ja va 2s. c o m InstanceIdentifier<DPNTEPsInfo> tunnelInfoId = InstanceIdentifier.builder(DpnEndpoints.class) .child(DPNTEPsInfo.class, new DPNTEPsInfoKey(dpnId)).build(); Optional<DPNTEPsInfo> tunnelInfo = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, tunnelInfoId); if (tunnelInfo.isPresent()) { List<TunnelEndPoints> nexthopIpList = tunnelInfo.get().getTunnelEndPoints(); if (nexthopIpList != null && !nexthopIpList.isEmpty()) { nextHopIp = new String(nexthopIpList.get(0).getIpAddress().getValue()); } } return nextHopIp; }
From source file:com.facebook.buck.apple.FrameworkPath.java
public static FrameworkPath fromString(BuildTarget target, String string) { Path path = Paths.get(string); String firstElement = Preconditions.checkNotNull(Iterables.getFirst(path, Paths.get(""))).toString(); if (firstElement.startsWith("$")) { // NOPMD - length() > 0 && charAt(0) == '$' is ridiculous Optional<PBXReference.SourceTree> sourceTree = PBXReference.SourceTree.fromBuildSetting(firstElement); if (sourceTree.isPresent()) { return ImmutableFrameworkPath.builder().setSourceTreePath( new SourceTreePath(sourceTree.get(), path.subpath(1, path.getNameCount()))).build(); } else {//w ww . j a v a 2 s .c om throw new HumanReadableException(String.format( "Unknown SourceTree: %s in target: %s. Should be one of: %s", firstElement, target, Joiner.on(',') .join(Iterables.transform(ImmutableList.copyOf(PBXReference.SourceTree.values()), new Function<PBXReference.SourceTree, String>() { @Override public String apply(PBXReference.SourceTree input) { return "$" + input.toString(); } })))); } } else { return ImmutableFrameworkPath.builder() .setSourcePath(new BuildTargetSourcePath(target, Paths.get(string))).build(); } }
From source file:net.pterodactylus.sonitus.io.IdentifyingInputStream.java
/** * Tries to identify the given input stream. * * @param inputStream//from w ww.j a v a 2 s. com * The input stream to identify * @return An identifying input stream that delivers the original stream and * the metadata it detected, or {@link Optional#absent()} if no * metadata could be identified * @throws IOException * if an I/O error occurs */ public static Optional<IdentifyingInputStream> create(InputStream inputStream) throws IOException { /* remember everything we read here. */ RememberingInputStream rememberingInputStream = new RememberingInputStream(inputStream); /* first, try formats with unambiguous layouts. */ try { Optional<Metadata> metadata = FlacIdentifier.identify(rememberingInputStream); if (metadata.isPresent()) { return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get())); } } catch (EOFException eofe1) { /* ignore. */ } /* try Ogg Vorbis next. */ try { rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered()); Optional<Metadata> metadata = OggVorbisIdentifier.identify(rememberingInputStream); if (metadata.isPresent()) { return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get())); } } catch (EOFException eofe1) { /* ignore. */ } /* finally, try MP3. */ try { rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered()); InputStream limitedInputStream = ByteStreams.limit(rememberingInputStream, 1048576); Optional<Metadata> metadata = Mp3Identifier.identify(limitedInputStream); if (metadata.isPresent()) { return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get())); } } catch (EOFException eofe1) { /* ignore. */ } return Optional.absent(); }
From source file:org.dswarm.graph.rdf.utils.NodeTypeUtils.java
public static Optional<NodeType> getNodeType(final Optional<RDFNode> optionalNode, final Optional<Boolean> optionalIsType) { if (!optionalNode.isPresent()) { return Optional.absent(); }//w w w .j av a2 s .c o m final NodeType nodeType; final RDFNode node = optionalNode.get(); if (node.isURIResource()) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.Resource; } else { nodeType = NodeType.TypeResource; } } else { nodeType = NodeType.Resource; } } else if (node.isAnon()) { if (optionalIsType.isPresent()) { if (Boolean.FALSE.equals(optionalIsType.get())) { nodeType = NodeType.BNode; } else { nodeType = NodeType.TypeBNode; } } else { nodeType = NodeType.BNode; } } else if (node.isLiteral()) { nodeType = NodeType.Literal; } else { nodeType = null; } return Optional.fromNullable(nodeType); }
From source file:org.apache.gobblin.runtime.job_spec.ResolvedJobSpec.java
private static Config resolveConfig(JobSpec jobSpec, JobCatalog catalog) throws SpecNotFoundException, JobTemplate.TemplateException { Optional<URI> templateURIOpt = jobSpec.getTemplateURI(); if (templateURIOpt.isPresent()) { JobCatalogWithTemplates catalogWithTemplates = new PackagedTemplatesJobCatalogDecorator(catalog); JobTemplate template = catalogWithTemplates.getTemplate(templateURIOpt.get()); return template.getResolvedConfig(jobSpec.getConfig()).resolve(); } else {// w ww . j av a 2 s .c o m return jobSpec.getConfig().resolve(); } }
From source file:gobblin.serde.HiveSerDeWrapper.java
/** * Get an instance of {@link HiveSerDeWrapper}. * * @param serDeType The SerDe type. If serDeType is one of the available {@link HiveSerDeWrapper.BuiltInHiveSerDe}, * the other three parameters are not used. Otherwise, serDeType should be the class name of a {@link SerDe}, * and the other three parameters must be present. *///from ww w . j av a 2s. c o m public static HiveSerDeWrapper get(String serDeType, Optional<String> inputFormatClassName, Optional<String> outputFormatClassName) { Optional<BuiltInHiveSerDe> hiveSerDe = Enums.getIfPresent(BuiltInHiveSerDe.class, serDeType.toUpperCase()); if (hiveSerDe.isPresent()) { return new HiveSerDeWrapper(hiveSerDe.get()); } else { Preconditions.checkArgument(inputFormatClassName.isPresent(), "Missing input format class name for SerDe " + serDeType); Preconditions.checkArgument(outputFormatClassName.isPresent(), "Missing output format class name for SerDe " + serDeType); return new HiveSerDeWrapper(serDeType, inputFormatClassName.get(), outputFormatClassName.get()); } }
From source file:org.opendaylight.yangtools.sal.binding.generator.impl.BindingSchemaContextUtils.java
private static DataNodeContainer findInCases(final ChoiceSchemaNode choiceNode, final QName targetQName) { for (ChoiceCaseNode caze : choiceNode.getCases()) { Optional<DataNodeContainer> potential = findDataNodeContainer(caze, targetQName); if (potential.isPresent()) { return potential.get(); }//from w w w.j a va2 s . c o m } return null; }
From source file:com.incapture.apigen.slate.gen.TypeNodeFactory.java
public static Collection<Node> createTypesNodes(Function function, TypesContainer typesContainer) { List<Node> nodes = new LinkedList<>(); List<Field> fields = new LinkedList<>(); fields.addAll(function.getParameters()); fields.add(function.getReturnType()); for (Field parameter : fields) { Optional<TypeDefinition> typeOptional = typesContainer.get(parameter.getPackageName(), parameter.getType());//w w w . j ava2 s .c om if (typeOptional.isPresent()) { //add some description TypeDefinition typeDefinition = typeOptional.get(); nodes.add(new HeaderNode(typeDefinition.getName(), 4)); nodes.add(new TextNode(String.format("*%s*", typeDefinition.getDocumentation()))); if (typeDefinition.isDeprecated()) { if (typeDefinition.getDeprecatedText() != null) { nodes.add(new AsideNode("This type is deprecated: " + typeDefinition.getDeprecatedText(), AsideNodeType.WARNING)); } else { nodes.add(new AsideNode("This type is deprecated.", AsideNodeType.WARNING)); } } nodes.add(new EmptyLineNode()); //add all the fields TableHeaderNode headerNode = new TableHeaderNode("Field", "Type"); TableNode tableNode = new TableNode(headerNode); for (Field field : typeDefinition.getFields()) { String text = field.getType(); //maybe add <a href=''... link here, to link to other types? tableNode.getRows().add(new TableRowNode(field.getName(), text)); } nodes.add(tableNode); nodes.add(new EmptyLineNode()); } } return nodes; }
From source file:com.palantir.atlasdb.keyvalue.cassandra.jmx.CassandraJmxCompactionManagers.java
/** * return a empty set if not client can be created * @param config/*from www . ja va 2 s.com*/ * @return */ public static Set<CassandraJmxCompactionClient> createCompactionClients(CassandraKeyValueServiceConfig config) { if (!config.jmx().isPresent()) { return Collections.emptySet(); } CassandraJmxCompactionConfig jmxConfig = config.jmx().get(); // need to set the property before creating the JMX compaction client setJmxSslProperty(jmxConfig); Set<CassandraJmxCompactionClient> clients = Sets.newHashSet(); Set<String> thriftEndPoints = config.servers(); Preconditions.checkState(!thriftEndPoints.isEmpty(), "address_list should not be empty."); // jmxEndPoints are using different ports specified in address_list int jmxPort = jmxConfig.port(); for (String endPointHost : thriftEndPoints) { Optional<CassandraJmxCompactionClient> client = new CassandraJmxCompactionClient.Builder(endPointHost, jmxPort).username(jmxConfig.username()).password(jmxConfig.password()).build(); if (client.isPresent()) { clients.add(client.get()); } } return clients; }
From source file:com.epam.reportportal.utils.properties.PropertiesLoader.java
/** * Try to load properties from file situated in the class path, and then * reload existing parameters from environment variables * * @return/*from w w w . j av a 2 s . c o m*/ * @throws IOException */ private static Properties loadProperties() throws IOException { Properties props = new Properties(); Optional<URL> propertyFile = getResource(INNER_PATH); if (propertyFile.isPresent()) { props.load(Resources.asByteSource(propertyFile.get()).openBufferedStream()); } reloadFromSystemProperties(props); reloadFromEnvVariables(props); reloadFromSoapUI(props); validateProperties(props); reloadProperties(props); setProxyProperties(props); return props; }