List of usage examples for java.util Collections singletonList
public static <T> List<T> singletonList(T o)
From source file:MainClass.java
public static void main(String[] a) { System.out.println(Collections.singletonList("a")); System.out.println(Collections.singleton("a")); System.out.println(Collections.singletonMap("a", "b")); }
From source file:Main.java
public static void main(String args[]) { // create an array of string objs String init[] = { "One", "Two", "Three", "One", "Two", "Three", "from java2s.com" }; // create one list List<String> list = new ArrayList<String>(Arrays.asList(init)); System.out.println("List value before: " + list); // create singleton list list = Collections.singletonList("One"); System.out.println("List value after: " + list); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEventWriter writer = XMLOutputFactory.newInstance().createXMLEventWriter(System.out); Namespace ns1 = eventFactory.createNamespace("ns1", "http://www.e.com/ns1"); Namespace ns2 = eventFactory.createNamespace("ns2", "http://www.e.com/ns2"); List<Namespace> namespaceList = new ArrayList<Namespace>(); namespaceList.add(ns1);// w w w.ja va 2 s. co m namespaceList.add(ns2); Attribute attribute = eventFactory.createAttribute(ns2.getPrefix(), ns2.getNamespaceURI(), "attribute", "true"); writer.add(eventFactory.createStartElement(ns1.getPrefix(), ns1.getNamespaceURI(), "sample", Collections.singletonList(attribute).iterator(), namespaceList.iterator())); writer.add(eventFactory.createEndDocument()); writer.flush(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String source = "<p xmlns='http://www.java2s.com/nfe' versao='2.00'></p>"; XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xPath = xPathFactory.newXPath(); NamespaceContext context = new NamespaceContext() { String PREFIX = "nfe"; String URI = "http://www.java2s.com/nfe"; @Override//from w w w. j a va 2s .co m public String getNamespaceURI(String prefix) { return (PREFIX.equals(prefix)) ? URI : XMLConstants.NULL_NS_URI; } @Override public String getPrefix(String namespaceUri) { return (URI.equals(namespaceUri)) ? PREFIX : XMLConstants.DEFAULT_NS_PREFIX; } @Override public Iterator getPrefixes(String namespaceUri) { return Collections.singletonList(this.getPrefix(namespaceUri)).iterator(); } }; xPath.setNamespaceContext(context); InputSource inputSource = new InputSource(new StringReader(source)); String versao = xPath.evaluate("//nfe:p/@versao", inputSource); System.out.println(versao.toString()); }
From source file:Main.java
public static void main(String[] args) throws Exception { KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA"); kpg.initialize(1024, new SecureRandom()); KeyPair dsaKeyPair = kpg.generateKeyPair(); XMLSignatureFactory sigFactory = XMLSignatureFactory.getInstance(); Reference ref = sigFactory.newReference("#Body", sigFactory.newDigestMethod(DigestMethod.SHA1, null)); SignedInfo signedInfo = sigFactory.newSignedInfo( sigFactory.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, (C14NMethodParameterSpec) null), sigFactory.newSignatureMethod(SignatureMethod.DSA_SHA1, null), Collections.singletonList(ref)); KeyInfoFactory kif = sigFactory.getKeyInfoFactory(); KeyValue kv = kif.newKeyValue(dsaKeyPair.getPublic()); KeyInfo keyInfo = kif.newKeyInfo(Collections.singletonList(kv)); XMLSignature xmlSig = sigFactory.newXMLSignature(signedInfo, keyInfo); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA"); kpg.initialize(1024, new SecureRandom()); KeyPair dsaKeyPair = kpg.generateKeyPair(); XMLSignatureFactory sigFactory = XMLSignatureFactory.getInstance(); Reference ref = sigFactory.newReference("#Body", sigFactory.newDigestMethod(DigestMethod.SHA1, null)); SignedInfo signedInfo = sigFactory.newSignedInfo( sigFactory.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, (C14NMethodParameterSpec) null), sigFactory.newSignatureMethod(SignatureMethod.DSA_SHA1, null), Collections.singletonList(ref)); KeyInfoFactory kif = sigFactory.getKeyInfoFactory(); KeyValue kv = kif.newKeyValue(dsaKeyPair.getPublic()); KeyInfo keyInfo = kif.newKeyInfo(Collections.singletonList(kv)); XMLSignature xmlSig = sigFactory.newXMLSignature(signedInfo, keyInfo); }
From source file:io.ingenieux.lambda.shell.LambdaShell.java
public static void main(String[] args) throws Exception { final Map<String, List<String>> result = new LambdaShell() .runCommands(Collections.singletonList("ps -aux")); System.err.println(result);// w w w. j a v a2 s. c o m }
From source file:com.example.bigtable.sample.CreateTable.java
public static void main(String[] args) throws Exception { Configuration conf = HBaseConfiguration.create(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 1) { System.err.println("Usage: <table-name>"); System.exit(2);//from w w w.j a v a2 s .c o m } TableName tableName = TableName.valueOf(otherArgs[otherArgs.length - 1]); createTable(tableName, conf, Collections.singletonList("cf")); }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step1PrepareContainers.java
public static void main(String[] args) throws IOException { // queries with narratives in CSV File queries = new File(args[0]); File relevantInformationExamplesFile = new File(args[1]); Map<Integer, Map<Integer, List<String>>> relevantInformationMap = parseRelevantInformationFile( relevantInformationExamplesFile); // output dir File outputDir = new File(args[2]); if (!outputDir.exists()) { outputDir.mkdirs();/* w ww. j a v a 2 s . c o m*/ } // iterate over queries CSVParser csvParser = CSVParser.parse(queries, Charset.forName("utf-8"), CSVFormat.DEFAULT); for (CSVRecord record : csvParser) { // create new container, fill, and store QueryResultContainer container = new QueryResultContainer(); container.qID = record.get(0); container.query = record.get(1); // Fill some dummy text first container.relevantInformationExamples.addAll(Collections.singletonList("ERROR. Information missing.")); container.irrelevantInformationExamples .addAll(Collections.singletonList("ERROR. Information missing.")); // and now fill it with existing information if available Integer queryID = Integer.valueOf(container.qID); if (relevantInformationMap.containsKey(queryID)) { if (relevantInformationMap.get(queryID).containsKey(0)) { container.irrelevantInformationExamples = new ArrayList<>( relevantInformationMap.get(queryID).get(0)); } if (relevantInformationMap.get(queryID).containsKey(1)) { container.relevantInformationExamples = new ArrayList<>( relevantInformationMap.get(queryID).get(1)); } } File outputFile = new File(outputDir, container.qID + ".xml"); FileUtils.writeStringToFile(outputFile, container.toXML()); System.out.println("Finished " + outputFile); } }
From source file:kafka.examples.consumer.BasicConsumerExample.java
public static void main(String[] args) { ArgumentParser parser = argParser(); try {//from ww w . j av a2 s . c o m Namespace res = parser.parseArgs(args); /* parse args */ String brokerList = res.getString("bootstrap.servers"); String topic = res.getString("topic"); String serializer = res.getString("serializer"); Properties consumerConfig = new Properties(); consumerConfig.put("group.id", "my-group"); consumerConfig.put("bootstrap.servers", brokerList); consumerConfig.put("auto.offset.reset", "earliest"); consumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer"); consumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer"); KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(consumerConfig); consumer.subscribe(Collections.singletonList(topic)); while (true) { ConsumerRecords<byte[], byte[]> records = consumer.poll(1000); for (ConsumerRecord<byte[], byte[]> record : records) { System.out.printf( "Received Message topic =%s, partition =%s, offset = %d, key = %s, value = %s\n", record.topic(), record.partition(), record.offset(), deserialize(record.key()), deserialize(record.value())); } consumer.commitSync(); } } catch (ArgumentParserException e) { if (args.length == 0) { parser.printHelp(); System.exit(0); } else { parser.handleError(e); System.exit(1); } } }