List of usage examples for java.util Iterator next
E next();
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramCount.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;//w w w . java2s . c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzeBigramCount.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); List<PairOfWritables<Text, IntWritable>> bigrams = SequenceFileUtils.readDirectory(new Path(inputPath)); Collections.sort(bigrams, new Comparator<PairOfWritables<Text, IntWritable>>() { public int compare(PairOfWritables<Text, IntWritable> e1, PairOfWritables<Text, IntWritable> e2) { if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); int singletons = 0; int sum = 0; for (PairOfWritables<Text, IntWritable> bigram : bigrams) { sum += bigram.getRightElement().get(); if (bigram.getRightElement().get() == 1) { singletons++; } } System.out.println("total number of unique bigrams: " + bigrams.size()); System.out.println("total number of bigrams: " + sum); System.out.println("number of bigrams that appear only once: " + singletons); System.out.println("\nten most frequent bigrams: "); Iterator<PairOfWritables<Text, IntWritable>> iter = Iterators.limit(bigrams.iterator(), 10); while (iter.hasNext()) { PairOfWritables<Text, IntWritable> bigram = iter.next(); System.out.println(bigram.getLeftElement() + "\t" + bigram.getRightElement()); } }
From source file:Main.java
public static void main(String args[]) { List<String[]> left = new ArrayList<String[]>(); left.add(new String[] { "one", "two" }); List<String[]> right = new ArrayList<String[]>(); right.add(new String[] { "one", "two" }); java.util.Iterator<String[]> leftIterator = left.iterator(); java.util.Iterator<String[]> rightIterator = right.iterator(); if (left.size() != right.size()) { System.out.println("not equal"); }/* w w w . j a v a 2 s.co m*/ while (leftIterator.hasNext()) { if (Arrays.equals(leftIterator.next(), rightIterator.next())) continue; else { System.out.print("not equal"); break; } } }
From source file:at.gv.egiz.pdfas.cli.test.SignaturProfileTest.java
public static void main(String[] args) { String user_home = System.getProperty("user.home"); String pdfas_dir = user_home + File.separator + ".pdfas"; PdfAs pdfas = PdfAsFactory.createPdfAs(new File(pdfas_dir)); try {//from www .j a v a 2s. c o m Configuration config = pdfas.getConfiguration(); ISettings settings = (ISettings) config; List<String> signatureProfiles = new ArrayList<String>(); List<String> signaturePDFAProfiles = new ArrayList<String>(); Iterator<String> itKeys = settings.getFirstLevelKeys("sig_obj.types.").iterator(); while (itKeys.hasNext()) { String key = itKeys.next(); String profile = key.substring("sig_obj.types.".length()); System.out.println("[" + profile + "]: " + settings.getValue(key)); if (settings.getValue(key).equals("on")) { signatureProfiles.add(profile); if (profile.contains("PDFA")) { signaturePDFAProfiles.add(profile); } } } byte[] input = IOUtils.toByteArray(new FileInputStream(sourcePDF)); IPlainSigner signer = new PAdESSignerKeystore(KS_FILE, KS_ALIAS, KS_PASS, KS_KEY_PASS, KS_TYPE); Iterator<String> itProfiles = signatureProfiles.iterator(); while (itProfiles.hasNext()) { String profile = itProfiles.next(); System.out.println("Testing " + profile); DataSource source = new ByteArrayDataSource(input); FileOutputStream fos = new FileOutputStream(targetFolder + profile + ".pdf"); SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos); signParameter.setPlainSigner(signer); signParameter.setSignatureProfileId(profile); SignResult result = pdfas.sign(signParameter); fos.close(); } byte[] inputPDFA = IOUtils.toByteArray(new FileInputStream(sourcePDFA)); Iterator<String> itPDFAProfiles = signaturePDFAProfiles.iterator(); while (itPDFAProfiles.hasNext()) { String profile = itPDFAProfiles.next(); System.out.println("Testing " + profile); DataSource source = new ByteArrayDataSource(inputPDFA); FileOutputStream fos = new FileOutputStream(targetFolder + "PDFA_" + profile + ".pdf"); SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos); signParameter.setPlainSigner(signer); signParameter.setSignatureProfileId(profile); SignResult result = pdfas.sign(signParameter); fos.close(); } } catch (Throwable e) { e.printStackTrace(); } }
From source file:dependencies.DependencyResolving.java
/** * @param args the command line arguments *///w w w.ja v a 2 s .c o m public static void main(String[] args) { // TODO code application logic here JSONParser parser = new JSONParser(); //we use JSONParser in order to be able to read from JSON file try { //here we declare the file reader and define the path to the file dependencies.json Object obj = parser.parse(new FileReader( "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\dependencies.json")); JSONObject project = (JSONObject) obj; //a JSON object containing all the data in the .json file JSONArray dependencies = (JSONArray) project.get("dependencies"); //get array of objects with key "dependencies" System.out.print("We need to install the following dependencies: "); Iterator<String> iterator = dependencies.iterator(); //define an iterator over the array "dependencies" while (iterator.hasNext()) { System.out.println(iterator.next()); } //on the next line we declare another object, which parses a Parser object and reads from all_packages.json Object obj2 = parser.parse(new FileReader( "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\all_packages.json")); JSONObject tools = (JSONObject) obj2; //a JSON object containing all thr data in the file all_packages.json for (int i = 0; i < dependencies.size(); i++) { if (tools.containsKey(dependencies.get(i))) { System.out.println( "In order to install " + dependencies.get(i) + ", we need the following programs:"); JSONArray temporaryArray = (JSONArray) tools.get(dependencies.get(i)); //a temporary JSON array in which we store the keys and values of the dependencies for (i = 0; i < temporaryArray.size(); i++) { System.out.println(temporaryArray.get(i)); } ArrayList<Object> arraysOfJsonData = new ArrayList<Object>(); //an array in which we will store the keys of the objects, after we use the values and won't need them anymore for (i = 0; i < temporaryArray.size(); i++) { System.out.println("Installing " + temporaryArray.get(i)); } while (!temporaryArray.isEmpty()) { for (Object element : temporaryArray) { if (tools.containsKey(element)) { JSONArray secondaryArray = (JSONArray) tools.get(element); //a temporary array within the scope of the if-statement if (secondaryArray.size() != 0) { System.out.println("In order to install " + element + ", we need "); } for (i = 0; i < secondaryArray.size(); i++) { System.out.println(secondaryArray.get(i)); } for (Object o : secondaryArray) { arraysOfJsonData.add(o); //here we create a file with the installed dependency File file = new File( "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\installed_modules\\" + o); if (file.createNewFile()) { System.out.println(file.getName() + " is installed!"); } else { } } secondaryArray.clear(); } } temporaryArray.clear(); for (i = 0; i < arraysOfJsonData.size(); i++) { temporaryArray.add(arraysOfJsonData.get(i)); } arraysOfJsonData.clear(); } } } Set<String> keys = tools.keySet(); // here we define a set of keys of the objects in all_packages.json for (String s : keys) { File file = new File( "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\installed_modules\\" + s); if (file.createNewFile()) { System.out.println(file.getName() + " is installed."); } else { } } } catch (IOException ex) { Logger.getLogger(DependencyResolving.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(DependencyResolving.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:jsonclient.JsonClient.java
public static void main(String args[]) { int EPS = 1;/*from w w w . j av a 2s. c o m*/ List<Place> countries = new ArrayList<Place>(); List<Thread> threads = new ArrayList<Thread>(); Country country; countries = getCountries(); //CountrySearcher countrySearcher = null; Iterator<Place> itrCountry = countries.iterator(); ExecutorService exec = Executors.newFixedThreadPool(4); while (itrCountry.hasNext()) { country = new Country(itrCountry.next()); CountrySearcher cs = new CountrySearcher(country, EPS); threads.add(cs.thread); exec.execute(cs); } exec.shutdown(); for (Thread th : threads) try { th.join(); } catch (InterruptedException ex) { Logger.getLogger(JsonClient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.mozilla.socorro.RawDumpSizeScan.java
public static void main(String[] args) throws ParseException { String startDateStr = args[0]; String endDateStr = args[1];//from w ww . j a va2s. co m // Set both start/end time and start/stop row Calendar startCal = Calendar.getInstance(); Calendar endCal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); if (!StringUtils.isBlank(startDateStr)) { startCal.setTime(sdf.parse(startDateStr)); } if (!StringUtils.isBlank(endDateStr)) { endCal.setTime(sdf.parse(endDateStr)); } DescriptiveStatistics stats = new DescriptiveStatistics(); long numNullRawBytes = 0L; HTable table = null; Map<String, Integer> rowValueSizeMap = new HashMap<String, Integer>(); try { table = new HTable(TABLE_NAME_CRASH_REPORTS); Scan[] scans = generateScans(startCal, endCal); for (Scan s : scans) { ResultScanner rs = table.getScanner(s); Iterator<Result> iter = rs.iterator(); while (iter.hasNext()) { Result r = iter.next(); ImmutableBytesWritable rawBytes = r.getBytes(); //length = r.getValue(RAW_DATA_BYTES, DUMP_BYTES); if (rawBytes != null) { int length = rawBytes.getLength(); if (length > 20971520) { rowValueSizeMap.put(new String(r.getRow()), length); } stats.addValue(length); } else { numNullRawBytes++; } if (stats.getN() % 10000 == 0) { System.out.println("Processed " + stats.getN()); System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", stats.getMin(), stats.getMax(), stats.getMean())); System.out.println( String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f", stats.getPercentile(25.0d), stats.getPercentile(50.0d), stats.getPercentile(75.0d))); System.out.println("Number of large entries: " + rowValueSizeMap.size()); } } rs.close(); } System.out.println("Finished Processing!"); System.out.println(String.format("Min: %.02f Max: %.02f Mean: %.02f", stats.getMin(), stats.getMax(), stats.getMean())); System.out.println(String.format("1st Quartile: %.02f 2nd Quartile: %.02f 3rd Quartile: %.02f", stats.getPercentile(25.0d), stats.getPercentile(50.0d), stats.getPercentile(75.0d))); for (Map.Entry<String, Integer> entry : rowValueSizeMap.entrySet()) { System.out.println(String.format("RowId: %s => Length: %d", entry.getKey(), entry.getValue())); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (table != null) { try { table.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:com.hp.avmon.snmp.discover.SLPClient.java
/** * Test method./*www .ja v a2 s .c om*/ * * @param args * Ignored */ public static void main(String[] args) { SLPClient client = new SLPClient(); List<String> wbemservices = client.findWbemServices(); Iterator<String> serviceIterator = wbemservices.iterator(); while (serviceIterator.hasNext()) { String url = serviceIterator.next().toString(); System.out.println(url); logger.debug(url); List<String> attributes = client.findAttributes(url, SCOPE, new Vector<String>()); Iterator<String> attributeIterator = attributes.iterator(); while (attributeIterator.hasNext()) { System.out.println(attributeIterator.next()); logger.debug(attributeIterator.next()); } } }
From source file:asl.seedscan.DQAWeb.java
public static void main(String args[]) { db = new MetricDatabase("", "", ""); findConsoleHandler();//from ww w . j av a 2 s . c o m consoleHandler.setLevel(Level.ALL); Logger.getLogger("").setLevel(Level.CONFIG); // Default locations of config and schema files File configFile = new File("dqaweb-config.xml"); File schemaFile = new File("schemas/DQAWebConfig.xsd"); boolean parseConfig = true; boolean testMode = false; ArrayList<File> schemaFiles = new ArrayList<File>(); schemaFiles.add(schemaFile); // ==== Command Line Parsing ==== Options options = new Options(); Option opConfigFile = new Option("c", "config-file", true, "The config file to use for seedscan. XML format according to SeedScanConfig.xsd."); Option opSchemaFile = new Option("s", "schema-file", true, "The schame file which should be used to verify the config file format. "); Option opTest = new Option("t", "test", false, "Run in test console mode rather than as a servlet."); OptionGroup ogConfig = new OptionGroup(); ogConfig.addOption(opConfigFile); OptionGroup ogSchema = new OptionGroup(); ogConfig.addOption(opSchemaFile); OptionGroup ogTest = new OptionGroup(); ogTest.addOption(opTest); options.addOptionGroup(ogConfig); options.addOptionGroup(ogSchema); options.addOptionGroup(ogTest); PosixParser optParser = new PosixParser(); CommandLine cmdLine = null; try { cmdLine = optParser.parse(options, args, true); } catch (org.apache.commons.cli.ParseException e) { logger.severe("Error while parsing command-line arguments."); System.exit(1); } Option opt; Iterator iter = cmdLine.iterator(); while (iter.hasNext()) { opt = (Option) iter.next(); if (opt.getOpt().equals("c")) { configFile = new File(opt.getValue()); } else if (opt.getOpt().equals("s")) { schemaFile = new File(opt.getValue()); } else if (opt.getOpt().equals("t")) { testMode = true; } } String query = ""; System.out.println("Entering Test Mode"); System.out.println("Enter a query string to view results or type \"help\" for example query strings"); InputStreamReader input = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(input); String result = ""; while (testMode == true) { try { System.out.printf("Query: "); query = reader.readLine(); if (query.equals("exit")) { testMode = false; } else if (query.equals("help")) { System.out.println("Need to add some help for people"); //TODO } else { result = processCommand(query); } System.out.println(result); } catch (IOException err) { System.err.println("Error reading line, in DQAWeb.java"); } } System.err.printf("DONE.\n"); }
From source file:net.wedjaa.elasticparser.tester.ESSearchTester.java
public static void main(String[] args) { System.out.println("ES Search Testing started."); System.out.println("Starting local node..."); Settings nodeSettings = ImmutableSettings.settingsBuilder().put("transport.tcp.port", "9600-9700") .put("http.port", "9500").put("http.max_content_length", "104857600").build(); Node node = NodeBuilder.nodeBuilder().settings(nodeSettings).clusterName("elasticparser.unittest").node(); node.start();// ww w. ja v a 2s .c om // Populate our test index System.out.println("Preparing Unit Test Index - this may take a while..."); populateTest(); try { System.out.println("...OK - Executing query!"); // Try our searches ESSearch search = new ESSearch(null, null, ESSearch.ES_MODE_AGGS, "localhost", 9600, "elasticparser.unittest"); search.search(getQuery("test-aggs.json")); Map<String, Object> hit = null; while ((hit = search.next()) != null) { System.out.println("Hit: {"); for (String key : hit.keySet()) { System.out.println(" " + key + ": " + hit.get(key)); } System.out.println("};"); } search.close(); Map<String, Class<?>> fields = search.getFields(getQuery("test-aggs.json")); List<String> sortedKeys = new ArrayList<String>(fields.keySet()); Collections.sort(sortedKeys); Iterator<String> sortedKeyIter = sortedKeys.iterator(); while (sortedKeyIter.hasNext()) { String fieldname = sortedKeyIter.next(); System.out.println(" --> " + fieldname + "[" + fields.get(fieldname).getCanonicalName() + "]"); } } catch (Exception ex) { System.out.println("Exception: " + ex); } finally { System.out.println("Stopping Test Node"); node.stop(); } }
From source file:com.mewmew.fairy.v1.book.Cut.java
public static void main(String[] args) throws FileNotFoundException { Iterator<Map<String, Object>> iter = new Cut(null) .createIterator(new FileInputStream("/Users/jax/.gconsole/caches/gonsole.xno.ningops.net.txt")); while (iter.hasNext()) { Map<String, Object> map = iter.next(); System.out.println(map);/*from w w w. java 2s .c om*/ } }