List of usage examples for java.util Iterator next
E next();
From source file:NumberTest.java
public static void main(String args[]) { args = new String[] { "number.json" }; for (int a = 0; a < args.length; a++) { System.out.println(args[a]); String version = "Unknown"; try {/*w w w.ja va2 s . c om*/ System.out.println("Starting"); JSONTokener tokener = new JSONTokener(new FileInputStream(args[a])); JSONObject jsonSubject = new JSONObject(tokener); System.out.println( jsonSubject.getJSONObject("MovieTexture").get("@startTime").getClass().getSimpleName()); JSONObject jsonSchema = new JSONObject( new JSONTokener(NumberTest.class.getResourceAsStream("numberschema.json"))); Schema schema = SchemaLoader.load(jsonSchema); schema.validate(jsonSubject); System.out.println("Finishing"); System.out.println("json-schema Valid " + args[a]); } catch (NullPointerException e) { System.out.println("json-config null point error " + args[a]); } catch (FileNotFoundException e) { System.out.println("json-file file missing " + e.getMessage() + " " + args[a]); } catch (JSONException je) { System.out.println("json-parse json " + je.getMessage() + " " + args[a]); } catch (ValidationException ve) { ve.printStackTrace(); System.out.println("json-schema Validation error " + ve + " " + args[a]); Iterator<ValidationException> i = ve.getCausingExceptions().iterator(); while (i.hasNext()) { ValidationException veel = i.next(); System.out.println("json-schema Validation error " + veel + " " + args[a]); } } } }
From source file:facade.examples.Collections.java
/** * Run the examples//from w w w.j av a 2 s .c o m * @param args <i>ignored</i> */ public static void main(String[] args) { /* RESISTORS IN PARALLEL WITH FACADE */ System.out.println("-> With facade: "); /* Empty collection of resistors */ Collection<Double> resistors = new ArrayList<Double>(); /* adding values. on() modifies the collection in place */ on(resistors).add(1.5, 3.0, 15.0, 30.0, 150.0); /* computing resistance. with() works on a collection copy. */ double r = 1.0 / with(resistors).map(inverse).reduce(sum); /* pretty printing the resistors */ System.out.println("[ " + with(resistors).join(", ") + " ]"); /* printing the equivalent resistor */ System.out.println(r); /* --------------------------------------------------------------- */ System.out.println(); /* --------------------------------------------------------------- */ /* RESISTORS IN PARALLEL WITH CLASSIC JAVA */ System.out.println("-> Without facade: "); /* Empty collection of resistors */ resistors = new ArrayList<Double>(); /* adding values */ resistors.add(1.5); resistors.add(3.0); resistors.add(15.0); resistors.add(30.0); resistors.add(150.0); /* computing resistance */ double sum = 0.0; for (Double resistor : resistors) { sum += 1.0 / resistor; } r = 1.0 / sum; /* pretty printing the resistors */ StringBuilder sb = new StringBuilder(); sb.append("[ "); Iterator<Double> it = resistors.iterator(); if (it.hasNext()) { sb.append(it.next()); } while (it.hasNext()) { sb.append(", ").append(it.next()); } sb.append(" ]"); System.out.println(sb.toString()); /* printing the equivalent resistor */ System.out.println(r); }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hashmap = new HashMap<String, String>(); hashmap.put("one", "1"); hashmap.put("two", "2"); hashmap.put("three", "3"); hashmap.put("four", "4"); hashmap.put("five", "5"); hashmap.put("six", "6"); Iterator<String> keyIterator = hashmap.keySet().iterator(); Iterator<String> valueIterator = hashmap.values().iterator(); while (keyIterator.hasNext()) { System.out.println("key: " + keyIterator.next()); }//from www. ja v a 2 s. c o m while (valueIterator.hasNext()) { System.out.println("value: " + valueIterator.next()); } }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> aList = new ArrayList<String>(); aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("5"); for (String str : aList) { System.out.println(str);// w w w .j a va2 s. c om } Iterator itr = aList.iterator(); // remove 2 from ArrayList using Iterator's remove method. String strElement = ""; while (itr.hasNext()) { strElement = (String) itr.next(); if (strElement.equals("2")) { itr.remove(); break; } } for (String str : aList) { System.out.println(str); } }
From source file:com.enitalk.controllers.youtube.CalendarTest.java
public static void main(String[] args) throws IOException { InputStream is = new ClassPathResource("events.json").getInputStream(); ObjectMapper jackson = new ObjectMapper(); JsonNode tree = jackson.readTree(is); IOUtils.closeQuietly(is);//from w ww .j a v a 2 s. c o m DateTimeFormatter fmtDateTime = ISODateTimeFormat.dateTimeNoMillis(); DateTimeFormatter fmt = ISODateTimeFormat.date(); TreeMultimap<DateTime, DateTime> set = CalendarTest.getPeriodSet(10, 18); Iterator<JsonNode> nodes = tree.elements(); while (nodes.hasNext()) { JsonNode ev = nodes.next(); boolean isFullDay = ev.path("start").has("date"); DateTime stDate = isFullDay ? fmt.parseDateTime(ev.path("start").path("date").asText()) : fmtDateTime.parseDateTime(ev.path("start").path("dateTime").asText()); DateTime enDate = isFullDay ? fmt.parseDateTime(ev.path("end").path("date").asText()) : fmtDateTime.parseDateTime(ev.path("end").path("dateTime").asText()); System.out.println("St " + stDate + " en " + enDate); int days = Days.daysBetween(stDate, enDate).getDays(); System.out.println("Days between " + days); if (isFullDay) { switch (days) { case 1: set.removeAll(stDate); break; default: while (days-- > 0) { set.removeAll(stDate.plusDays(days)); } } } else { DateTime copySt = stDate.minuteOfHour().setCopy(0).secondOfMinute().setCopy(0); DateTime copyEn = enDate.plusHours(1).minuteOfHour().setCopy(0).secondOfMinute().setCopy(0); // System.out.println("Dates truncated " + copySt + " " + copyEn); // System.out.println("Ll set " + set); // System.out.println("Getting set for key " + stDate.millisOfDay().setCopy(0)); SortedSet<DateTime> ss = set.get(stDate.millisOfDay().setCopy(0)); SortedSet<DateTime> subset = ss.subSet(copySt, copyEn); subset.clear(); set.remove(enDate.millisOfDay().setCopy(0), copyEn); } } }
From source file:CSVSimple.java
public static void main(String[] args) { CSV parser = new CSV(); List list = parser.parse("\"LU\",86.25,\"11/4/1998\",\"2:19PM\",+4.0625"); Iterator it = list.iterator(); while (it.hasNext()) { System.out.println(it.next()); }//from www.ja v a 2 s . c o m // Now test with a non-default separator parser = new CSV('|'); list = parser.parse("\"LU\"|86.25|\"11/4/1998\"|\"2:19PM\"|+4.0625"); it = list.iterator(); while (it.hasNext()) { System.out.println(it.next()); } }
From source file:com.bright.utils.rmDuplicateLines.java
public static void main(String args) { File monfile = new File(args); Set<String> userIdSet = new LinkedHashSet<String>(); if (monfile.isFile() && monfile.getName().endsWith(".txt")) { try {/*ww w .ja va2 s .c o m*/ List<String> content = FileUtils.readLines(monfile, Charset.forName("UTF-8")); userIdSet.addAll(content); Iterator<String> itr = userIdSet.iterator(); StringBuffer output = new StringBuffer(); while (itr.hasNext()) { output.append(itr.next() + System.getProperty("line.separator")); } BufferedWriter out = new BufferedWriter(new FileWriter(monfile)); String outText = output.toString(); out.write(outText); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.ning.metrics.collector.util.LocalFileReader.java
public static void main(String[] args) throws IOException { InputStream stream = null;//from w w w. ja v a 2 s. c o m try { stream = new BufferedInputStream(new FileInputStream(args[0])); final SmileEnvelopeEventDeserializer deserializer = new SmileEnvelopeEventDeserializer(stream, false); while (deserializer.hasNextEvent()) { final SmileEnvelopeEvent event = deserializer.getNextEvent(); final JsonNode node = (JsonNode) event.getData(); final Iterator<JsonNode> elements = node.elements(); boolean first = true; while (elements.hasNext()) { final JsonNode jsonNode = elements.next(); if (!first) { System.out.print(","); } System.out.print(jsonNode.toString()); first = false; } System.out.print("\n"); } } finally { if (stream != null) { stream.close(); } System.out.flush(); } }
From source file:listfiles.ListFiles.java
/** * @param args the command line arguments *///from w w w. j av a2 s. c o m public static void main(String[] args) { // TODO code application logic here BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String folderPath = ""; String fileName = "DirectoryFiles.xlsx"; try { System.out.println("Folder path :"); folderPath = reader.readLine(); //System.out.println("Output File Name :"); //fileName = reader.readLine(); XSSFWorkbook wb = new XSSFWorkbook(); FileOutputStream fileOut = new FileOutputStream(folderPath + "\\" + fileName); XSSFSheet sheet1 = wb.createSheet("Files"); int row = 0; Stream<Path> stream = Files.walk(Paths.get(folderPath)); Iterator<Path> pathIt = stream.iterator(); String ext = ""; while (pathIt.hasNext()) { Path filePath = pathIt.next(); Cell cell1 = checkRowCellExists(sheet1, row, 0); Cell cell2 = checkRowCellExists(sheet1, row, 1); row++; ext = FilenameUtils.getExtension(filePath.getFileName().toString()); cell1.setCellValue(filePath.getFileName().toString()); cell2.setCellValue(ext); } sheet1.autoSizeColumn(0); sheet1.autoSizeColumn(1); wb.write(fileOut); fileOut.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("Program Finished"); }
From source file:com.berrysys.ussdgw.Starter.java
/** * The main method./* w w w .j a v a2 s .c om*/ * * @param args the arguments * @throws IOException Signals that an I/O exception has occurred. */ public static void main(String[] args) throws IOException { StringBuilder banner = new StringBuilder(); banner.append("\n").append(" ____ ____ \n") .append(" | __ ) ___ _ __ _ __ _ _/ ___| _ _ ___ \n") .append(" | _ \\ / _ \\ '__| '__| | | \\___ \\| | | / __|\n") .append(" | |_) | __/ | | | | |_| |___) | |_| \\__ \\\n") .append(" |____/ \\___|_| _|_| \\__, |____/ \\__, |___/\n") .append(" / ___|(_) __ _| |_ _ _|___/_ _ __ |___/ \n") .append(" \\___ \\| |/ _` | __| '__/ _` | '_ \\ \n") .append(" ___) | | (_| | |_| | | (_| | | | | \n") .append(" |____/|_|\\__, |\\__|_| \\__,_|_| |_| \n") .append(" _ _ __|___/__ ____ \n") .append(" | | | / ___/ ___|| _ \\ \n") .append(" | | | \\___ \\___ \\| | | | \n") .append(" | |_| |___) |__) | |_| | \n") .append(" \\___/|____/____/|____/ \n") .append(" / ___| __ _| |_ _____ ____ _ _ _ \n") .append(" | | _ / _` | __/ _ \\ \\ /\\ / / _` | | | | \n") .append(" | |_| | (_| | || __/\\ V V / (_| | |_| | \n") .append(" \\____|\\__,_|\\__\\___| \\_/\\_/ \\__,_|\\__, |\n") .append(" |___/ \n"); String berrysysUssdGW = banner.toString(); log.info(berrysysUssdGW); ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/app-context.xml"); List<DialogListener> serverList = (List<DialogListener>) applicationContext.getBean("sctpServerList"); Iterator<DialogListener> i = serverList.iterator(); while (i.hasNext()) { final DialogListener dialogListenerItem = i.next(); DialogListenerThread dialogListenerThread = new DialogListenerThread(); dialogListenerThread.setDialogListener(dialogListenerItem); dialogListenerThread.start(); ThreadHolder.getInstance().getDialogListenerThreadList().add(dialogListenerThread); } Iterator<DialogListenerThread> j = ThreadHolder.getInstance().getDialogListenerThreadList().iterator(); while (j.hasNext()) { try { j.next().join(); } catch (InterruptedException e) { log.catching(e); } } }