List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:SetDemo.java
public static void main(String[] argv) { //+//w ww . j a v a 2s.com Set h = new HashSet(); h.add("One"); h.add("Two"); h.add("One"); // DUPLICATE h.add("Three"); Iterator it = h.iterator(); while (it.hasNext()) { System.out.println(it.next()); } //- }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.RecommendationToJson.java
public static void main(String[] args) throws IOException { final int TOTAL_WORDS = 20; String host = args[0];//from w ww .j a v a2 s . c o m int port = Integer.parseInt(args[1]); Jedis jedis = new Jedis(host, port, 20000); String[] recommendation_keys = jedis.keys("recommendations_*").toArray(new String[0]); for (int i = 0; i < recommendation_keys.length; ++i) { JSONArray recommendations = new JSONArray(); String[] split_reco_name = recommendation_keys[i].split("_"); String id = split_reco_name[split_reco_name.length - 1]; Set<Tuple> recos = jedis.zrangeWithScores(recommendation_keys[i], 0, -1); Iterator<Tuple> it = recos.iterator(); while (it.hasNext()) { Tuple t = it.next(); JSONObject new_reco = new JSONObject(); new_reco.put("id", t.getElement()); new_reco.put("distance", (double) Math.round(t.getScore() * 10000) / 10000); recommendations.add(new_reco); } saveResults(recommendations, id); } jedis.disconnect(); }
From source file:IteratorEnumeration.java
public static void main(String[] args) { Set<String> set = new HashSet<String>(); set.add("a"); set.add("b"); set.add("c"); set.add("d"); Enumeration<String> x = new IteratorEnumeration<String>(set.iterator()); while (x.hasMoreElements()) { System.out.println(x.nextElement()); }/* ww w . j ava 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { Set<String> set = new LinkedHashSet<String>(); // Add some elements set.add("1"); set.add("2"); set.add("3"); set.add("2"); // List the elements for (Iterator it = set.iterator(); it.hasNext();) { Object o = it.next();// ww w . j a v a 2 s .c om } }
From source file:com.impetus.kvapps.runner.AppRunner.java
/** * main runner method/* ww w .j ava 2s . c o m*/ * @param args takes excel data file as input argument args[0]. */ public static void main(String[] args) { // Override CQL version while instantiating entity manager factory. EntityManagerFactory emf = Persistence.createEntityManagerFactory("twissandra,twingo,twirdbms"); EntityManager em = emf.createEntityManager(); try { //populate user set from excel sheet. Set<User> users = UserBroker.brokeUserList(args[0]); for (Iterator<User> iterator = users.iterator(); iterator.hasNext();) { User user = (User) iterator.next(); // on Persist ExecutorService.onPersist(em, user); // on find by id. ExecutorService.findByKey(em, "BigDataUser"); List<User> fetchedUsers = ExecutorService.onQueryByEmail(em, user); if (fetchedUsers != null && fetchedUsers.size() > 0) { logger.info(user.toString()); } logger.info(""); System.out.println("#######################Querying##########################################"); logger.info(""); logger.info(""); } // Execute wild search query. String query = "Select u from User u"; logger.info(query); ExecutorService.findByQuery(em, query); // // Execute native CQL. Fetch tweets for given user. logger.info(""); System.out.println("#######################Querying##########################################"); logger.info(""); logger.info(""); query = "Select * from tweets where user_id='RDBMSUser'"; logger.info(query); ExecutorService.findByNativeQuery(em, query); } finally { onDestroyDBResources(emf, em); } }
From source file:SetDemo.java
public static void main(String[] args) { String[] letters = { "A", "B", "C", "D", "E" }; Set s = new HashSet(); for (int i = 0; i < letters.length; i++) s.add(letters[i]);/* w w w . j a v a 2 s. co m*/ if (!s.add(letters[0])) System.out.println("Cannot add a duplicate.\n"); Iterator iter = s.iterator(); while (iter.hasNext()) System.out.println(iter.next()); System.out.println(""); SortedSet ss = new TreeSet(); for (int i = 0; i < letters.length; i++) ss.add(letters[i]); if (!ss.add(letters[0])) System.out.println("Cannot add a duplicate.\n"); iter = ss.iterator(); while (iter.hasNext()) System.out.println(iter.next()); }
From source file:GetWebPageApp.java
public static void main(String args[]) throws Exception { String resource, host, file;// w w w . jav a2 s . c om int slashPos; resource = "www.java2s.com/index.htm"; // skip HTTP:// slashPos = resource.indexOf('/'); // find host/file separator if (slashPos < 0) { resource = resource + "/"; slashPos = resource.indexOf('/'); } file = resource.substring(slashPos); // isolate host and file parts host = resource.substring(0, slashPos); System.out.println("Host to contact: '" + host + "'"); System.out.println("File to fetch : '" + file + "'"); SocketChannel channel = null; try { Charset charset = Charset.forName("ISO-8859-1"); CharsetDecoder decoder = charset.newDecoder(); CharsetEncoder encoder = charset.newEncoder(); ByteBuffer buffer = ByteBuffer.allocateDirect(1024); CharBuffer charBuffer = CharBuffer.allocate(1024); InetSocketAddress socketAddress = new InetSocketAddress(host, 80); channel = SocketChannel.open(); channel.configureBlocking(false); channel.connect(socketAddress); selector = Selector.open(); channel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ); while (selector.select(500) > 0) { Set readyKeys = selector.selectedKeys(); try { Iterator readyItor = readyKeys.iterator(); while (readyItor.hasNext()) { SelectionKey key = (SelectionKey) readyItor.next(); readyItor.remove(); SocketChannel keyChannel = (SocketChannel) key.channel(); if (key.isConnectable()) { if (keyChannel.isConnectionPending()) { keyChannel.finishConnect(); } String request = "GET " + file + " \r\n\r\n"; keyChannel.write(encoder.encode(CharBuffer.wrap(request))); } else if (key.isReadable()) { keyChannel.read(buffer); buffer.flip(); decoder.decode(buffer, charBuffer, false); charBuffer.flip(); System.out.print(charBuffer); buffer.clear(); charBuffer.clear(); } else { System.err.println("Unknown key"); } } } catch (ConcurrentModificationException e) { } } } catch (UnknownHostException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); } finally { if (channel != null) { try { channel.close(); } catch (IOException ignored) { } } } System.out.println("\nDone."); }
From source file:MainClass.java
public static void main(String args[]) { Set simpsons = new HashSet(); simpsons.add("B"); simpsons.add("H"); simpsons.add("L"); simpsons = Collections.synchronizedSet(simpsons); synchronized (simpsons) { Iterator iter = simpsons.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/* w w w. ja v a 2s . c o m*/ } Map map = Collections.synchronizedMap(new HashMap(89)); Set set = map.entrySet(); synchronized (map) { Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } } }
From source file:ItemSet.java
public static void main(String args[]) { String names[] = { "Item 1", "Item 2", "Item 3" }; Set moons = new HashSet(); int namesLen = names.length; int index;// w w w . j a v a2s .c om for (int i = 0; i < 100; i++) { index = (int) (Math.random() * namesLen); moons.add(names[index]); } Iterator it = moons.iterator(); while (it.hasNext()) { System.out.println(it.next()); } System.out.println("---"); Set orderedMoons = new TreeSet(moons); it = orderedMoons.iterator(); while (it.hasNext()) { System.out.println(it.next()); } }
From source file:com.cloud.test.utils.SubmitCert.java
public static void main(String[] args) { // Parameters List<String> argsList = Arrays.asList(args); Iterator<String> iter = argsList.iterator(); while (iter.hasNext()) { String arg = iter.next(); if (arg.equals("-c")) { certFileName = iter.next();// ww w. jav a 2s .co m } if (arg.equals("-s")) { secretKey = iter.next(); } if (arg.equals("-a")) { apiKey = iter.next(); } if (arg.equals("-action")) { url = "Action=" + iter.next(); } } Properties prop = new Properties(); try { prop.load(new FileInputStream("conf/tool.properties")); } catch (IOException ex) { s_logger.error("Error reading from conf/tool.properties", ex); System.exit(2); } host = prop.getProperty("host"); port = prop.getProperty("port"); if (url.equals("Action=SetCertificate") && certFileName == null) { s_logger.error("Please set path to certificate (including file name) with -c option"); System.exit(1); } if (secretKey == null) { s_logger.error("Please set secretkey with -s option"); System.exit(1); } if (apiKey == null) { s_logger.error("Please set apikey with -a option"); System.exit(1); } if (host == null) { s_logger.error("Please set host in tool.properties file"); System.exit(1); } if (port == null) { s_logger.error("Please set port in tool.properties file"); System.exit(1); } TreeMap<String, String> param = new TreeMap<String, String>(); String req = "GET\n" + host + ":" + prop.getProperty("port") + "\n/" + prop.getProperty("accesspoint") + "\n"; String temp = ""; if (certFileName != null) { cert = readCert(certFileName); param.put("cert", cert); } param.put("AWSAccessKeyId", apiKey); param.put("Expires", prop.getProperty("expires")); param.put("SignatureMethod", prop.getProperty("signaturemethod")); param.put("SignatureVersion", "2"); param.put("Version", prop.getProperty("version")); StringTokenizer str1 = new StringTokenizer(url, "&"); while (str1.hasMoreTokens()) { String newEl = str1.nextToken(); StringTokenizer str2 = new StringTokenizer(newEl, "="); String name = str2.nextToken(); String value = str2.nextToken(); param.put(name, value); } //sort url hash map by key Set c = param.entrySet(); Iterator it = c.iterator(); while (it.hasNext()) { Map.Entry me = (Map.Entry) it.next(); String key = (String) me.getKey(); String value = (String) me.getValue(); try { temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&"; } catch (Exception ex) { s_logger.error("Unable to set parameter " + value + " for the command " + param.get("command"), ex); } } temp = temp.substring(0, temp.length() - 1); String requestToSign = req + temp; String signature = UtilsForTest.signRequest(requestToSign, secretKey); String encodedSignature = ""; try { encodedSignature = URLEncoder.encode(signature, "UTF-8"); } catch (Exception ex) { ex.printStackTrace(); } String url = "http://" + host + ":" + prop.getProperty("port") + "/" + prop.getProperty("accesspoint") + "?" + temp + "&Signature=" + encodedSignature; s_logger.info("Sending request with url: " + url + "\n"); sendRequest(url); }