List of usage examples for java.util Iterator next
E next();
From source file:LinkedListTest.java
public static void main(String[] args) { List<String> a = new LinkedList<String>(); a.add("Amy"); a.add("Carl"); a.add("Erica"); List<String> b = new LinkedList<String>(); b.add("Bob"); b.add("Doug"); b.add("Frances"); b.add("Gloria"); // merge the words from b into a ListIterator<String> aIter = a.listIterator(); Iterator<String> bIter = b.iterator(); while (bIter.hasNext()) { if (aIter.hasNext()) aIter.next();// w w w . j a v a 2s. c om aIter.add(bIter.next()); } System.out.println(a); // remove every second word from b bIter = b.iterator(); while (bIter.hasNext()) { bIter.next(); // skip one element if (bIter.hasNext()) { bIter.next(); // skip next element bIter.remove(); // remove that element } } System.out.println(b); // bulk operation: remove all words in b from a a.removeAll(b); System.out.println(a); }
From source file:edu.jhu.hlt.concrete.ingesters.alnc.ALNCIngesterRunner.java
/** * @param args// w ww . 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:Main.java
public static void main(String[] argv) throws Exception { ImageInputStream imageStream = ImageIO.createImageInputStream(new URL("").openStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(imageStream); ImageReader reader = null;/*from ww w . j ava2 s .c o m*/ if (!readers.hasNext()) { imageStream.close(); return; } else { reader = readers.next(); } String formatName = reader.getFormatName(); if (!formatName.equalsIgnoreCase("jpeg") && !formatName.equalsIgnoreCase("png") && !formatName.equalsIgnoreCase("gif")) { imageStream.close(); return; } reader.setInput(imageStream, true, true); BufferedImage theImage = reader.read(0); reader.dispose(); imageStream.close(); }
From source file:com.cedarsoft.serialization.SplittingPerformanceRunner.java
public static void main(String[] args) throws Exception { final String uri = "http://www.cedarsoft.com/some/slashes/1.0.0"; run("String.plit", new Callable<String>() { @Override//from w w w . j a v a2 s .c om public String call() throws Exception { String[] parts = uri.split("/"); return parts[parts.length - 1]; } }); run("Splitter", new Callable<String>() { @Override public String call() throws Exception { Splitter splitter = Splitter.on("/"); Iterable<String> parts = splitter.split(uri); Iterator<String> iterator = parts.iterator(); while (true) { String current = iterator.next(); if (!iterator.hasNext()) { return current; } } } }); run("static Splitter", new Callable<String>() { @Override public String call() throws Exception { Iterable<String> parts = SPLITTER.split(uri); Iterator<String> iterator = parts.iterator(); while (true) { String current = iterator.next(); if (!iterator.hasNext()) { return current; } } } }); run("indexOf", new Callable<String>() { @Override public String call() throws Exception { int index = uri.lastIndexOf("/"); return uri.substring(index + 1); } }); }
From source file:OldStyle.java
public static void main(String args[]) { ArrayList list = new ArrayList(); // These lines store strings, but any type of object // can be stored. In old-style code, there is no // convenient way restrict the type of objects stored // in a collection list.add("one"); list.add("two"); list.add("three"); list.add("four"); Iterator itr = list.iterator(); while (itr.hasNext()) { // To retrieve an element, an explicit type cast is needed // because the collection stores only Object. String str = (String) itr.next(); // explicit cast needed here. System.out.println(str + " is " + str.length() + " chars long."); }//from ww w . ja v a 2 s . c o m }
From source file:ListAlgorithms.java
public static void main(String[] args) { Provider[] providers = Security.getProviders(); Set<String> ciphers = new HashSet<String>(); Set<String> keyAgreements = new HashSet<String>(); Set<String> macs = new HashSet<String>(); Set<String> messageDigests = new HashSet<String>(); Set<String> signatures = new HashSet<String>(); for (int i = 0; i != providers.length; i++) { Iterator it = providers[i].keySet().iterator(); while (it.hasNext()) { String entry = (String) it.next(); if (entry.startsWith("Alg.Alias.")) { entry = entry.substring("Alg.Alias.".length()); }/*from www . j a va 2s. co m*/ if (entry.startsWith("Cipher.")) { ciphers.add(entry.substring("Cipher.".length())); } else if (entry.startsWith("KeyAgreement.")) { keyAgreements.add(entry.substring("KeyAgreement.".length())); } else if (entry.startsWith("Mac.")) { macs.add(entry.substring("Mac.".length())); } else if (entry.startsWith("MessageDigest.")) { messageDigests.add(entry.substring("MessageDigest.".length())); } else if (entry.startsWith("Signature.")) { signatures.add(entry.substring("Signature.".length())); } } } printSet("Ciphers", ciphers); printSet("KeyAgreeents", keyAgreements); printSet("Macs", macs); printSet("MessageDigests", messageDigests); printSet("Signatures", signatures); }
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); }/* ww w .jav a 2 s . c o m*/ System.out.println("received: " + reply); }
From source file:be.redlab.maven.yamlprops.create.YamlConvertCli.java
public static void main(String... args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert") .longOpt("source").hasArg(true).build()); options.addOption(Option.builder("t").argName("target").desc("the target file to store in") .longOpt("target").hasArg(true).build()); options.addOption(Option.builder("h").desc("print help").build()); try {//from w w w . ja va2 s . c om CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { formatter.printHelp("converter", options); } File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir"))); String name = source.getName(); if (source.isDirectory()) { PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter(); String[] ext = { "properties" }; Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true); while (fileIterator.hasNext()) { File next = fileIterator.next(); System.out.println(next); String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath()); System.out.println(s); String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0]; System.out.println("key = " + f); Properties p = new Properties(); try { p.load(new FileReader(next)); yamlConverter.addProperties(f, p); } catch (IOException e) { e.printStackTrace(); } } FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); yamlConverter.writeYaml(fileWriter); fileWriter.close(); } else { Properties p = new Properties(); p.load(new FileReader(source)); FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter); fileWriter.close(); } } catch (ParseException e) { e.printStackTrace(); formatter.printHelp("converter", options); } }
From source file:edu.cmu.sv.modelinference.runner.Main.java
public static void main(String[] args) { Options cmdOpts = createCmdOptions(); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;// ww w . j a va 2s. co m try { cmd = parser.parse(cmdOpts, args, true); } catch (ParseException exp) { logger.error(exp.getMessage()); System.err.println(exp.getMessage()); Util.printHelpAndExit(Main.class, cmdOpts); } String inputType = cmd.getOptionValue(INPUT_TYPE_ARG); String tool = cmd.getOptionValue(TOOL_TYPE_ARG); String logFile = cmd.getOptionValue(LOG_FILE_ARG).replaceFirst("^~", System.getProperty("user.home")); LogHandler<?> logHandler = null; boolean found = false; for (LogHandler<?> lh : logHandlers) { if (lh.getHandlerName().equals(tool)) { logHandler = lh; found = true; break; } } if (!found) { StringBuilder sb = new StringBuilder(); Iterator<LogHandler<?>> logIter = logHandlers.iterator(); while (logIter.hasNext()) { sb.append(logIter.next().getHandlerName()); if (logIter.hasNext()) sb.append(", "); } logger.error("Did not find tool for arg " + tool); System.err.println("Supported tools: " + Util.getSupportedHandlersString(logHandlers)); Util.printHelpAndExit(Main.class, cmdOpts); } logger.info("Using loghandler for logtype: " + logHandler.getHandlerName()); logHandler.process(logFile, inputType, cmd.getArgs()); }
From source file:x595.Main.java
public static void main(String... args) { @SuppressWarnings("resource") ApplicationContext ctx = new AnnotationConfigApplicationContext(JpaConfig.class); CarRepository repo = ctx.getBean(CarRepository.class); log("Start testing CarRepository"); LicenceInfo info1 = new LicenceInfo("Jane Doe", "jane@corp.com", new Date(), "N17D3E"); LicenceInfo info2 = new LicenceInfo("Josh Maxwell", "josh@googol.com", new Date(), "G99331"); LicenceInfo info3 = new LicenceInfo("JD", "saxe@me.com", new Date(), "HL9010"); LicenceInfo info4 = new LicenceInfo("Triple corp", "triple@doodle.org", new Date(), "JDC13X"); LicenceInfo info5 = new LicenceInfo("JD", "pro4@k5.com", new Date(), "A75Dc1"); Car c1 = new Car("AMG", "A4", 2012, 110, info1); Car c2 = new Car("Genesis", "G20", 2008, 170, info2); Car c3 = new Car("Lena", "sigma", 2015, 150, info3); Car c4 = new Car("AMG", "A7", 2010, 130, info4); Car c5 = new Car("Tesla", "T1", 2011, 90, info5); log("Part 0. insert cars"); repo.save(c1);/*from w w w. ja va 2 s.c om*/ repo.save(c2); repo.save(c3); repo.save(c4); repo.save(c5); Iterator<Car> it = repo.findAll().iterator(); log("Part 0. result of inserted car: "); while (it.hasNext()) { log(it.next().toString()); } log("Part 1. findByOrderByMakerAsc"); it = repo.findByOrderByMakerAsc().iterator(); log("Result: "); while (it.hasNext()) { log(it.next().toString()); } log("Part 2. findByLicenseInfoOwnerName"); it = repo.findByLicenseInfoOwnerName("JD").iterator(); log("Result: "); while (it.hasNext()) { log(it.next().toString()); } log("Part 3. findByMaker"); it = repo.findByMaker("AMG").iterator(); log("Result: "); while (it.hasNext()) { log(it.next().toString()); } log("Part 4. findByMakeYearBetween"); it = repo.findByMakeYearBetween(2010, 2013).iterator(); log("Result: "); while (it.hasNext()) { log(it.next().toString()); } log("Part 5. findByLicenseInfoLicensePlateNumber"); Car c = repo.findByLicenseInfoLicensePlateNumber("HL9010"); log("Result: "); log(c.toString()); }