List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:Main.java
public static void main(String[] args) { // Create a list of strings List<String> names = new ArrayList<>(); names.add("A"); names.add("B"); names.add("C"); // Get an iterator for the list Iterator<String> nameIterator = names.iterator(); // Iterate over all elements in the list while (nameIterator.hasNext()) { // Get the next element from the list String name = nameIterator.next(); System.out.println(name); }//from w ww . j ava 2 s . c o m }
From source file:au.org.ala.layers.client.Client.java
public static void main(String[] args) { System.out.println("Layers Store CLI client"); ApplicationContext context = new ClassPathXmlApplicationContext("spring/app-config.xml"); LayerDAO layerDao = (LayerDAO) context.getBean("layerDao"); List<Layer> layers = layerDao.getLayers(); System.out.println("Got " + layers.size() + " layers"); Iterator<Layer> it = layers.iterator(); while (it.hasNext()) { Layer l = it.next();//from ww w.j a v a2 s.co m System.out.println(" > " + l.getName()); } }
From source file:net.sourceforge.happybank.facade.BankTest.java
/** * Test method./*from ww w.ja va 2 s . co m*/ * * @param args command line arguments */ public static void main(final String[] args) { try { // get context and facade ApplicationContext ctx = new FileSystemXmlApplicationContext("build/applicationContext.xml"); BankingFacade bank = (BankingFacade) ctx.getBean("bankManager"); // get all customers List<Customer> customers = bank.getCustomers(); Iterator<Customer> custIter = customers.iterator(); Customer cust = null; while (custIter.hasNext()) { cust = custIter.next(); String cid = cust.getId(); Customer customer = bank.getCustomer(cid); System.out.println(customer.toString()); // get customers accounts List<Account> accounts = bank.getAccounts(cid); Iterator<Account> accIter = accounts.iterator(); Account acc = null; while (accIter.hasNext()) { acc = accIter.next(); String aid = acc.getId(); Account account = bank.getAccount(aid); System.out.println("\t> " + account.toString()); // get account transactions List<TransRecord> transactions = bank.getTransactions(aid); Iterator<TransRecord> transIter = transactions.iterator(); TransRecord tr = null; while (transIter.hasNext()) { tr = transIter.next(); System.out.println("\t\t>" + tr.toString()); } } } // test creation, deletion and withdrawal bank.addCustomer("999", "Mr", "First", "Last"); bank.addAccount("999-99", "999", "Checking"); bank.deposit("999-99", new BigDecimal(1000.0)); bank.withdraw("999-99", new BigDecimal(500.0)); bank.deleteAccount("999-99"); bank.deleteCustomer("999"); } catch (BankException ex) { ex.printStackTrace(); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.entropy.MatrixExperiments.java
public static void main(String[] args) throws Exception { File in = new File(args[0]); List<String> lines = IOUtils.readLines(new FileInputStream(in)); int rows = lines.size(); int cols = lines.iterator().next().split("\\s+").length; double[][] matrix = new double[rows][cols]; Map<Integer, Double> clusterEntropy = new HashMap<>(); for (int i = 0; i < rows; i++) { String line = lines.get(i); String[] split = line.split("\\s+"); for (int j = 0; j < split.length; j++) { Double value = Double.valueOf(split[j]); matrix[i][j] = value;//w w w. j a va2 s . co m } // entropy of the cluster Vector v = new DenseVector(matrix[i]); // System.out.print(VectorUtils.entropy(v)); double entropy = VectorUtils.entropy(VectorUtils.normalize(v)); System.out.print(entropy); System.out.print(" "); clusterEntropy.put(i, entropy); } Map<Integer, Double> sorted = sortByValue(clusterEntropy); System.out.println(sorted); HeatChart map = new HeatChart(matrix); // Step 2: Customise the chart. map.setTitle("This is my heat chart title"); map.setXAxisLabel("X Axis"); map.setYAxisLabel("Y Axis"); // Step 3: Output the chart to a file. map.saveToFile(new File("/tmp/java-heat-chart.png")); }
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 w w w .ja va 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.berrysys.ussdgw.Starter.java
/** * The main method./* w w w. j a va 2 s. c o m*/ * * @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) { List<String> syncList = Collections.synchronizedList(new ArrayList<String>()); syncList.add("one"); syncList.add("two"); syncList.add("three"); synchronized (syncList) { Iterator<String> iterator = syncList.iterator(); while (iterator.hasNext()) { System.out.println("item: " + iterator.next()); }// ww w. j a va2s . c om } }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLEventWriter writer = outputFactory.createXMLEventWriter(System.out); XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance(); StartDocument startDocument = xmlEventFactory.createStartDocument("UTF-8", "1.0"); writer.add(startDocument);/*from www . jav a 2s .c om*/ StartElement startElement = xmlEventFactory.createStartElement("", "", "My-list"); writer.add(startElement); Attribute attribute = xmlEventFactory.createAttribute("version", "1"); List attributeList = Arrays.asList(attribute); List nsList = Arrays.asList(); StartElement startElement2 = xmlEventFactory.createStartElement("", "", "Item", attributeList.iterator(), nsList.iterator()); writer.add(startElement2); StartElement codeSE = xmlEventFactory.createStartElement("", "", "code"); writer.add(codeSE); Characters codeChars = xmlEventFactory.createCharacters("I001"); writer.add(codeChars); EndElement codeEE = xmlEventFactory.createEndElement("", "", "code"); writer.add(codeEE); StartElement nameSE = xmlEventFactory.createStartElement(" ", " ", "name"); writer.add(nameSE); Characters nameChars = xmlEventFactory.createCharacters("a name"); writer.add(nameChars); EndElement nameEE = xmlEventFactory.createEndElement("", "", "name"); writer.add(nameEE); StartElement contactSE = xmlEventFactory.createStartElement("", "", "contact"); writer.add(contactSE); Characters contactChars = xmlEventFactory.createCharacters("another name"); writer.add(contactChars); EndElement contactEE = xmlEventFactory.createEndElement("", "", "contact"); writer.add(contactEE); EndDocument ed = xmlEventFactory.createEndDocument(); writer.add(ed); writer.flush(); writer.close(); }
From source file:ShowImage.java
public static void main(String args[]) throws IOException { List<File> files = ImageIOUtils.getFiles(args, new String[] { "ntf", "nsf" }); for (Iterator iter = files.iterator(); iter.hasNext();) { try {/*from w w w.ja v a2 s .co m*/ File file = (File) iter.next(); log.debug("Reading: " + file.getAbsolutePath()); NITFReader imageReader = (NITFReader) ImageIOUtils.getImageReader("nitf", file); for (int i = 0; i < imageReader.getRecord().getImages().length; ++i) { log.debug(file.getName() + "[" + i + "]"); ByteArrayOutputStream stream = new ByteArrayOutputStream(); ImageSubheader subheader = imageReader.getRecord().getImages()[i].getSubheader(); subheader.print(new PrintStream(stream)); log.debug(stream.toString()); try { int numBands = subheader.getBandCount(); String irep = subheader.getImageRepresentation().getStringData().trim(); int bitsPerPixel = subheader.getNumBitsPerPixel().getIntData(); int nBytes = (bitsPerPixel - 1) / 8 + 1; if (irep.equals("RGB") && numBands == 3) { BufferedImage image = imageReader.read(i); ImageIOUtils.showImage(image, file.getName() + "[" + i + "]", true); } else { // read each band, separately for (int j = 0; j < numBands; ++j) { if (nBytes == 1 || nBytes == 2 || nBytes == 4 || nBytes == 8) { ImageReadParam readParam = imageReader.getDefaultReadParam(); readParam.setSourceBands(new int[] { j }); BufferedImage image = imageReader.read(i, readParam); ImageIOUtils.showImage(image, file.getName() + "[" + i + "][" + j + "]", true); ImageIO.write(image, "jpg", new FileOutputStream("image" + i + "_" + j + ".jpg")); // downsample // readParam.setSourceSubsampling(2, 2, 0, // 0); // BufferedImage smallerImage = imageReader // .read(i, readParam); // // ImageIOUtils.showImage(smallerImage, // "DOWNSAMPLED: " + file.getName()); } } } } catch (Exception e) { System.out.println(ExceptionUtils.getStackTrace(e)); log.error(ExceptionUtils.getStackTrace(e)); } } } catch (Exception e) { log.debug(ExceptionUtils.getStackTrace(e)); } } }
From source file:XMLEventWriterDemo.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLEventWriter writer = outputFactory.createXMLEventWriter(System.out); XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance(); StartDocument startDocument = xmlEventFactory.createStartDocument("UTF-8", "1.0"); writer.add(startDocument);/*from w w w .j a v a2 s .c o m*/ StartElement startElement = xmlEventFactory.createStartElement("", "", "My-list"); writer.add(startElement); Attribute attribute = xmlEventFactory.createAttribute("version", "1"); List attributeList = Arrays.asList(attribute); List nsList = Arrays.asList(); StartElement startElement2 = xmlEventFactory.createStartElement("", "", "Item", attributeList.iterator(), nsList.iterator()); writer.add(startElement2); StartElement codeSE = xmlEventFactory.createStartElement("", "", "code"); writer.add(codeSE); Characters codeChars = xmlEventFactory.createCharacters("I001"); writer.add(codeChars); EndElement codeEE = xmlEventFactory.createEndElement("", "", "code"); writer.add(codeEE); StartElement nameSE = xmlEventFactory.createStartElement(" ", " ", "name"); writer.add(nameSE); Characters nameChars = xmlEventFactory.createCharacters("a name"); writer.add(nameChars); EndElement nameEE = xmlEventFactory.createEndElement("", "", "name"); writer.add(nameEE); StartElement contactSE = xmlEventFactory.createStartElement("", "", "contact"); writer.add(contactSE); Characters contactChars = xmlEventFactory.createCharacters("another name"); writer.add(contactChars); EndElement contactEE = xmlEventFactory.createEndElement("", "", "contact"); writer.add(contactEE); EndDocument ed = xmlEventFactory.createEndDocument(); writer.add(ed); writer.flush(); writer.close(); }