List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:TimeTrial.java
public static void main(String[] args) { StopWatch stWatch = new StopWatch(); // Start StopWatch stWatch.start();//from w w w.j a va2 s .c om // Get iterator for all days in a week starting Monday Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY); while (itr.hasNext()) { Calendar gCal = (Calendar) itr.next(); System.out.println(gCal.getTime()); } // Stop StopWatch stWatch.stop(); System.out.println("Time Taken >>" + stWatch.getTime()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Selector selector = Selector.open(); ServerSocketChannel ssChannel1 = ServerSocketChannel.open(); ssChannel1.configureBlocking(false); ssChannel1.socket().bind(new InetSocketAddress(80)); ServerSocketChannel ssChannel2 = ServerSocketChannel.open(); ssChannel2.configureBlocking(false); ssChannel2.socket().bind(new InetSocketAddress(81)); ssChannel1.register(selector, SelectionKey.OP_ACCEPT); ssChannel2.register(selector, SelectionKey.OP_ACCEPT); while (true) { selector.select();// w ww . j a v a2s . c om Iterator it = selector.selectedKeys().iterator(); while (it.hasNext()) { SelectionKey selKey = (SelectionKey) it.next(); it.remove(); if (selKey.isAcceptable()) { ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); SocketChannel sc = ssChannel.accept(); ByteBuffer buf = ByteBuffer.allocate(100); int numBytesRead = sc.read(buf); if (numBytesRead == -1) { sc.close(); } else { // Read the bytes from the buffer } int numBytesWritten = sc.write(buf); } } } }
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"); 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); nameIterator.remove();// ww w . ja va 2 s . c o m } System.out.println(names); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/* w ww. j a v a 2 s .c om*/ treeadd.add(13); treeadd.add(17); treeadd.add(2); // creating reverse set TreeSet<Integer> treereverse = (TreeSet<Integer>) treeadd.descendingSet(); // create descending set Iterator<Integer> iterator = treereverse.iterator(); //Tree set data in reverse order while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:InstanceOfDemo.java
/** * Demo method.//w w w. j a v a 2 s . c o m * * @param args Command Line arguments. */ public static void main(final String[] args) { final Iterator iter = OBJECT_SET.iterator(); Object obj = null; while (iter.hasNext()) { obj = iter.next(); if (obj instanceof Number) { System.out.println(obj); } } }
From source file:com.github.xbn.examples.io.non_xbn.SizeOrderAllFilesInDirXmpl.java
public static final void main(String[] ignored) { File fDir = (new File("R:\\jeffy\\programming\\sandbox\\xbnjava\\xbn\\")); Collection<File> cllf = FileUtils.listFiles(fDir, (new String[] { "java" }), true); //Add all file paths to a Map, keyed by size. //It's actually a map of lists-of-files, to //allow multiple files that happen to have the //same length. TreeMap<Long, List<File>> tmFilesBySize = new TreeMap<Long, List<File>>(); Iterator<File> itrf = cllf.iterator(); while (itrf.hasNext()) { File f = itrf.next();//from ww w . java 2s. c o m Long LLen = f.length(); if (!tmFilesBySize.containsKey(LLen)) { ArrayList<File> alf = new ArrayList<File>(); alf.add(f); tmFilesBySize.put(LLen, alf); } else { tmFilesBySize.get(LLen).add(f); } } //Iterate backwards by key through the map. For each //List<File>, iterate through the files, printing out //its size and path. ArrayList<Long> alSize = new ArrayList<Long>(tmFilesBySize.keySet()); for (int i = alSize.size() - 1; i >= 0; i--) { itrf = tmFilesBySize.get(alSize.get(i)).iterator(); while (itrf.hasNext()) { File f = itrf.next(); System.out.println(f.length() + ": " + f.getPath()); } } }
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();/* w ww . jav a 2 s . com*/ System.out.println(" > " + l.getName()); } }
From source file:com.discursive.jccook.xml.bardsearch.TermFreq.java
public static void main(String[] pArgs) throws Exception { logger.info("Threshold is 200"); Integer threshold = new Integer(200); IndexReader reader = IndexReader.open("index"); TermEnum enumVar = reader.terms();/* w w w . j av a 2s .c om*/ List termList = new ArrayList(); while (enumVar.next()) { if (enumVar.docFreq() >= threshold.intValue() && enumVar.term().field().equals("speech")) { Freq freq = new Freq(enumVar.term().text(), enumVar.docFreq()); termList.add(freq); } } Collections.sort(termList); Collections.reverse(termList); System.out.println("Frequency | Term"); Iterator iterator = termList.iterator(); while (iterator.hasNext()) { Freq freq = (Freq) iterator.next(); System.out.print(freq.frequency); System.out.println(" | " + freq.term); } }
From source file:Main.java
public static void main(String[] args) { String html = "<!html>" + "<html><body>" + "<span id='my'>" + "<span class=''contentTitle'>Director:</span>" + "<span>test</span></span>" + "</body></html>"; Document doc = Jsoup.parse(html); System.out.println(doc.toString()); Elements spanWithId = doc.select("span#my"); if (spanWithId != null) { System.out.printf("Found %d Elements\n", spanWithId.size()); if (!spanWithId.isEmpty()) { Iterator<Element> it = spanWithId.iterator(); Element element = null; while (it.hasNext()) { element = it.next();// www. ja v a 2 s. co m System.out.println(element.toString()); } } } }
From source file:NewFingerServer.java
public static void main(String[] arguments) throws Exception { ServerSocketChannel sockChannel = ServerSocketChannel.open(); sockChannel.configureBlocking(false); InetSocketAddress server = new InetSocketAddress("localhost", 79); ServerSocket socket = sockChannel.socket(); socket.bind(server);/*from w w w . j a v a 2 s .c o m*/ Selector selector = Selector.open(); sockChannel.register(selector, SelectionKey.OP_ACCEPT); while (true) { selector.select(); Set keys = selector.selectedKeys(); Iterator it = keys.iterator(); while (it.hasNext()) { SelectionKey selKey = (SelectionKey) it.next(); it.remove(); if (selKey.isAcceptable()) { ServerSocketChannel selChannel = (ServerSocketChannel) selKey.channel(); ServerSocket selSocket = selChannel.socket(); Socket connection = selSocket.accept(); InputStreamReader isr = new InputStreamReader(connection.getInputStream()); BufferedReader is = new BufferedReader(isr); PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()), false); pw.println("NIO Finger Server"); pw.flush(); String outLine = null; String inLine = is.readLine(); if (inLine.length() > 0) { outLine = inLine; } readPlan(outLine, pw); pw.flush(); pw.close(); is.close(); connection.close(); } } } }