List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:com.ning.metrics.collector.util.LocalFileReader.java
public static void main(String[] args) throws IOException { InputStream stream = null;//w w w . jav a2s. 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:com.berrysys.ussdgw.Starter.java
/** * The main method./*from ww w . j a v a 2 s . com*/ * * @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); } } }
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);/*from w w w . j a v a 2 s.c o m*/ } 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.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 {//from www . j a va2 s. co 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:edu.jhu.hlt.concrete.ingesters.alnc.ALNCIngesterRunner.java
/** * @param args// w w w .j a v a 2 s.c o m */ public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); ALNCIngesterRunner run = new ALNCIngesterRunner(); JCommander jc = new JCommander(run, args); jc.setProgramName(ALNCIngesterRunner.class.getSimpleName()); if (run.delegate.help) { jc.usage(); } try { Path outpath = Paths.get(run.delegate.outputPath); IngesterParameterDelegate.prepare(outpath); for (String pstr : run.delegate.paths) { LOGGER.debug("Running on file: {}", pstr); Path p = Paths.get(pstr); new ExistingNonDirectoryFile(p); Path outWithExt = outpath.resolve(p.getFileName() + ".tar.gz"); if (Files.exists(outWithExt)) { if (!run.delegate.overwrite) { LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString()); continue; } else { Files.delete(outWithExt); } } try (ALNCIngester ing = new ALNCIngester(p); OutputStream os = Files.newOutputStream(outWithExt); GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os); TarArchiver arch = new TarArchiver(gout)) { Iterator<Communication> iter = ing.iterator(); while (iter.hasNext()) { Communication c = iter.next(); LOGGER.debug("Got comm: {}", c.getId()); arch.addEntry(new ArchivableCommunication(c)); } } catch (IngestException e) { LOGGER.error("Caught exception processing path: " + pstr, e); } } } catch (NotFileException | IOException e) { LOGGER.error("Caught exception processing.", e); } }
From source file:listfiles.ListFiles.java
/** * @param args the command line arguments *//*from w w w . j a va 2 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: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 ww w .j a v a2 s . c om // 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.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 ww w .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:facade.examples.Collections.java
/** * Run the examples//from w w w.j a v a 2s .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:com.apress.prospringintegration.messagehistory.MessageHistoryApp.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:messagehistory/message-history-context.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); input.send(MessageBuilder.withPayload("Pro Spring Integration Example").build()); Message<?> reply = output.receive(); Iterator<Properties> historyIterator = reply.getHeaders() .get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator(); while (historyIterator.hasNext()) { Properties properties = historyIterator.next(); System.out.println(properties); }//w w w . j a v a2 s . c o m System.out.println("received: " + reply); }