List of usage examples for java.util TreeSet iterator
public Iterator<E> iterator()
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(12);//from w w w . j a v a 2 s . c o m treeadd.add(13); treeadd.add(14); treeadd.add(15); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(12);//from ww w .j ava 2s .co m treeadd.add(13); treeadd.add(14); treeadd.add(15); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } treeadd.clear(); System.out.println(treeadd.size()); }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/*from w w w. j ava2s. c o m*/ treeadd.add(3); treeadd.add(17); treeadd.add(2); System.out.println("Last element is: " + treeadd.pollLast()); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);//from ww w. ja v a 2s.co m treeadd.add(3); treeadd.add(17); treeadd.add(2); System.out.println("First element is: " + treeadd.pollFirst()); Iterator<Integer> iterator = treeadd.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeone = new TreeSet<Integer>(); TreeSet<Integer> treetwo = new TreeSet<Integer>(); treeone.add(12);//from ww w.j a v a2s . c o m treeone.add(13); treeone.add(14); treetwo.add(15); treetwo.add(16); treetwo.add(17); // adding treetwo to treeone treeone.addAll(treetwo); Iterator<Integer> iterator = treeone.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next()); } }
From source file:TreeSetDemo.java
public static void main(String[] argv) { //+/* w w w . j a va2 s .co m*/ /* * A TreeSet keeps objects in sorted order. We use a Comparator * published by String for case-insensitive sorting order. */ TreeSet tm = new TreeSet(String.CASE_INSENSITIVE_ORDER); tm.add("Gosling"); tm.add("da Vinci"); tm.add("van Gogh"); tm.add("Java To Go"); tm.add("Vanguard"); tm.add("Darwin"); tm.add("Darwin"); // TreeSet is Set, ignores duplicates. // Since it is sorted we can ask for various subsets System.out.println("Lowest (alphabetically) is " + tm.first()); // Print how many elements are greater than "k" System.out.println(tm.tailSet("k").toArray().length + " elements higher than \"k\""); // Print the whole list in sorted order System.out.println("Sorted list:"); java.util.Iterator t = tm.iterator(); while (t.hasNext()) System.out.println(t.next()); //- }
From source file:org.commoncrawl.util.MultiFileMergeUtils.java
public static void main(String[] args) { Path testPath = new Path(args[0]); LOG.info("Initializing Hadoop Config"); Configuration conf = new Configuration(); conf.addResource("nutch-default.xml"); conf.addResource("nutch-site.xml"); conf.addResource("mapred-site.xml"); conf.addResource("hdfs-site.xml"); conf.addResource("commoncrawl-default.xml"); conf.addResource("commoncrawl-site.xml"); conf.setClass(MultiFileInputReader.MULTIFILE_COMPARATOR_CLASS, URLFPV2RawComparator.class, RawComparator.class); conf.setClass(MultiFileInputReader.MULTIFILE_KEY_CLASS, URLFPV2.class, WritableComparable.class); CrawlEnvironment.setHadoopConfig(conf); CrawlEnvironment.setDefaultHadoopFSURI("hdfs://ccn01:9000/"); try {//from w w w. ja v a 2 s .c om FileSystem fs = CrawlEnvironment.getDefaultFileSystem(); Vector<Path> paths = new Vector<Path>(); paths.add(new Path(testPath, "part-00000")); // paths.add(new Path(testPath,"part-00000")); paths.add(new Path(testPath, "part-00001")); TreeSet<URLFPV2> directReadSet = new TreeSet<URLFPV2>(); TreeSet<URLFPV2> multiFileReadSet = new TreeSet<URLFPV2>(); MultiFileInputReader<URLFPV2> inputReader = new MultiFileInputReader<URLFPV2>(fs, paths, conf); KeyAndValueData<URLFPV2> keyValueData = null; int multiFileKeyCount = 0; while ((keyValueData = inputReader.readNextItem()) != null) { LOG.info("Got Key Domain:" + keyValueData._keyObject.getDomainHash() + " URLHash:" + keyValueData._keyObject.getUrlHash() + " Item Count:" + keyValueData._values.size() + " Path[0]:" + keyValueData._values.get(0).source); if (keyValueData._values.size() > 1) { LOG.error("Got more than one item"); for (int i = 0; i < keyValueData._values.size(); ++i) { CRC32 crc = new CRC32(); crc.update(keyValueData._keyData.getData(), 0, keyValueData._keyData.getLength()); LOG.error("Item at[" + i + "] Path:" + keyValueData._values.get(i).source + " CRC:" + crc.getValue()); } } if (multiFileKeyCount++ < 1000) multiFileReadSet.add((URLFPV2) keyValueData._keyObject.clone()); } inputReader.close(); addFirstNFPItemsToSet(fs, new Path(testPath, "part-00000"), conf, directReadSet, 1000); addFirstNFPItemsToSet(fs, new Path(testPath, "part-00001"), conf, directReadSet, 1000); Iterator<URLFPV2> directReadIterator = directReadSet.iterator(); Iterator<URLFPV2> multiFileReadIterator = multiFileReadSet.iterator(); for (int i = 0; i < 1000; ++i) { URLFPV2 directReadFP = directReadIterator.next(); URLFPV2 multiFileReadFP = multiFileReadIterator.next(); if (directReadFP.compareTo(multiFileReadFP) != 0) { LOG.info("Mismatch at Index:" + i); } } } catch (IOException e) { LOG.error(CCStringUtils.stringifyException(e)); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
/** * Return serializable data, the format of these data is placed like the following format * ${key}=${value}// w ww .j a va2 s . co m * * @param properties Properties instance * @return serializable data * @throws java.io.UnsupportedEncodingException * if errors occure during text converted to UTF-8 encoding */ public static byte[] getSerializablePropertiesData(Properties properties) throws UnsupportedEncodingException { Set keySet = properties.keySet(); TreeSet keys = new TreeSet(keySet); Iterator it = keys.iterator(); StringBuffer bf = new StringBuffer(); while (it.hasNext()) { String item = (String) it.next(); String resourceValue = (String) properties.get(item); bf.append(item); bf.append("="); bf.append(resourceValue); bf.append("\n"); } return bf.toString().getBytes("UTF-8"); }
From source file:uf.edu.AddLocation.java
public static String getLocation(TreeSet<String> APs) { Iterator<String> itr = APs.iterator(); JSONArray wifiaps = new JSONArray(); String out = null;/*from w w w .j a v a 2s. c o m*/ //put mac address in the json array while (itr.hasNext()) { JSONObject wifiap = new JSONObject(); try { wifiap.put("mac_address", (String) itr.next()); //TODO: add signal strength } catch (JSONException e) { Log.i(TAG, "AddLocation: Exception" + e.getMessage()); e.printStackTrace(); } wifiaps.put(wifiap); } //Adding rest of the data to create a complete Jason Package JSONObject obj = new JSONObject(); try { obj.put("version", "1.1.0"); obj.put("request_address", true); obj.put("wifi_towers", wifiaps); } catch (JSONException e) { Log.i(TAG, "AddLocation: Exception" + e.getMessage()); } //Now ask the Google Server for address. JSONObject output = SendHttpPost(url, obj); if (output == null) { return null; } //Parse out the address. try { out = ((JSONObject) output.get("location")).get("latitude") + "," + ((JSONObject) output.get("location")).get("longitude"); } catch (Exception e) { Log.i(TAG, "AddLocation: Exception parsing JSON " + e.getMessage()); } try { out = out + "," + ((JSONObject) output.get("location")).get("accuracy"); } catch (Exception e) { Log.i(TAG, "AddLocation: Exception parsing JSON " + e.getMessage()); } /* try{ JSONObject address = ((JSONObject)((JSONObject)output.get("location")).get("address")); try{ out = out +","+ address.get("street_number") + "," + address.get("street")+"," + address.get("postal_code"); } catch (Exception e) { Log.i(TAG,"AddLocation: Exception parsing JSON " + e.getMessage()); } try{ out =out +","+ address.get("city") +","+ address.get("county")+","+ address.get("region")+","+ address.get("country")+","+address.get("country_code") +"\n"; } catch (Exception e) { Log.i(TAG,"AddLocation: Exception parsing JSON " + e.getMessage()); } Iterator<String> it = address.keys(); while(it.hasNext()){ Log.i(TAG,"AddLocation: Key iterator: " + it.next()); } } catch (Exception e) { Log.i(TAG,"AddLocation: Exception parsing JSON " + e.getMessage()); } */ Log.i(TAG, "AddLocation: " + out); return out; }
From source file:org.openhab.binding.network.service.NetworkUtils.java
/** * Takes the interfaceIPs and fetches every IP which can be assigned on their network * * @param networkIPs The IPs which are assigned to the Network Interfaces * @return Every single IP which can be assigned on the Networks the computer is connected to *//*from w ww .j a v a 2 s . c o m*/ public static LinkedHashSet<String> getNetworkIPs(TreeSet<String> interfaceIPs) { LinkedHashSet<String> networkIPs = new LinkedHashSet<String>(); for (Iterator<String> it = interfaceIPs.iterator(); it.hasNext();) { try { // gets every ip which can be assigned on the given network SubnetUtils utils = new SubnetUtils(it.next()); String[] addresses = utils.getInfo().getAllAddresses(); for (int i = 0; i < addresses.length; i++) { networkIPs.add(addresses[i]); } } catch (Exception ex) { } } return networkIPs; }