List of usage examples for java.util Set size
int size();
From source file:SequentialPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(//from ww w. j ava 2s .c o m OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute PageRank. PageRank<String, Integer> ranker = new PageRank<String, Integer>(graph, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }
From source file:MainClass.java
public static void main(String[] argv) { Map map = new MyMap(); map.put("Adobe", "Mountain View, CA"); map.put("Learning Tree", "Los Angeles, CA"); map.put("IBM", "White Plains, NY"); String queryString = "Google"; System.out.println("You asked about " + queryString + "."); String resultString = (String) map.get(queryString); System.out.println("They are located in: " + resultString); System.out.println();/*from w w w .j ava 2 s .co m*/ Iterator k = map.keySet().iterator(); while (k.hasNext()) { String key = (String) k.next(); System.out.println("Key " + key + "; Value " + (String) map.get(key)); } Set es = map.entrySet(); System.out.println("entrySet() returns " + es.size() + " Map.Entry's"); }
From source file:FindDups.java
public static void main(String args[]) { Set s = new HashSet(); String[] values = new String[] { "java", "java2", "java2s", "javas", "java" }; for (int i = 0; i < values.length; i++) if (!s.add(values[i])) System.out.println("Duplicate detected: " + values[i]); System.out.println(s.size() + " distinct words detected: " + s); }
From source file:com.ettoremastrogiacomo.sktradingjava.starters.Temp.java
public static void main(String[] args) throws Exception { TreeSet<UDate> d = Database.getIntradayDates(); ArrayList<TreeSet<UDate>> m = timesegments(d, 1000 * 60 * 60 * 24 * 5); m.forEach((x) -> {//from w w w. j av a 2 s. c o m LOG.debug(x.size() + "\t" + x); }); Set l = longestSet(m); LOG.debug(l.size() + "\t" + l); // testCookies(); //LOG.debug(Database.getGoogleQuotes("BIT:ENEL")); /*java.util.HashMap<String,TreeSet<UDate>> map=new HashMap<String, TreeSet<UDate>>(); map=Database.intradayDates(); for (String h : map.keySet()){ TreeSet<UDate> ts= map.get(h); ts.forEach((d)->{LOG.debug(h+"\t"+d);}); }*/ if (true) return; //fetchEuroNext(); //Fints f=Database.getFintsQuotes(Optional.of("XMIB"),Optional.of("MLSE") , Optional.empty()); //f.getSerieCopy(3).plot("xmib", "price"); //LOG.debug(Database.getGoogleQuotes("BIT:ENEL")); // LOG.debug(com.ettoremastrogiacomo.utils.Encoding.base64encode(com.ettoremastrogiacomo.utils.Encoding.getSHA1("prova".getBytes())));; }
From source file:com.hillert.spring.validation.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from w w w.ja v a 2 s. c om*/ */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome! " + "\n " + "\n For more information please visit: " + "\n http://blog.hillert.com " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in).useDelimiter("\n"); final BusinessService service = context.getBean(BusinessService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a string and press <enter>: "); while (true) { System.out.print("$ "); String input = scanner.nextLine(); LOGGER.debug("Input string: '{}'", input); if ("q".equalsIgnoreCase(input)) { break; } else if ("null".equals(input)) { input = null; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (MethodConstraintViolationException e) { Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size()); for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) { LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor()); } } } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:SequentialPersonalizedPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(/*from w ww . j ava2 s .co m*/ OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); options.addOption(OptionBuilder.withArgName("node").hasArg() .withDescription("source node (i.e., destination of the random jump)").create(SOURCE)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(SOURCE)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPersonalizedPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); final String source = cmdline.getOptionValue(SOURCE); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); if (!graph.containsVertex(source)) { System.err.println("Error: source node not found in the graph!"); System.exit(-1); } WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute personalized PageRank. PageRankWithPriors<String, Integer> ranker = new PageRankWithPriors<String, Integer>(graph, new Transformer<String, Double>() { @Override public Double transform(String vertex) { return vertex.equals(source) ? 1.0 : 0; } }, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }
From source file:edu.umd.shrawanraina.SequentialPersonalizedPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(// w ww . ja v a 2 s . c o m OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); options.addOption(OptionBuilder.withArgName("node").hasArg() .withDescription("source node (i.e., destination of the random jump)").create(SOURCE)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(SOURCE)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPersonalizedPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); final String source = cmdline.getOptionValue(SOURCE); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); if (!graph.containsVertex(source)) { System.err.println("Error: source node not found in the graph!"); System.exit(-1); } WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute personalized PageRank. PageRankWithPriors<String, Integer> ranker = new PageRankWithPriors<String, Integer>(graph, new Transformer<String, Double>() { public Double transform(String vertex) { return vertex.equals(source) ? 1.0 : 0; } }, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }
From source file:com.somnus.spring.validation.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w ww . j av a 2s . c om */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome! " + "\n " + "\n For more information please visit: " + "\n http://blog.hillert.com " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in).useDelimiter("\n"); final BusinessService service = context.getBean(BusinessService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a string and press <enter>: "); while (true) { System.out.print("$ "); String input = scanner.nextLine(); LOGGER.debug("Input string: '{}'", input); if ("q".equalsIgnoreCase(input)) { break; } else if ("null".equals(input)) { input = null; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (MethodConstraintViolationException e) { Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size()); for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) { LOGGER.info("Method Validation: {}", violation.getPropertyPath().toString()); LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor()); LOGGER.info("Method Validation: {}", violation.getMessage()); } } } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:MainClass.java
public static void main(String args[]) { String[] name1 = { "Amy", "Jose", "Jeremy", "Alice", "Patrick" }; String[] name2 = { "Alan", "Amy", "Jeremy", "Helen", "Alexi" }; String[] name3 = { "Adel", "Aaron", "Amy", "James", "Alice" }; Set<String> letter = new HashSet<String>(); for (int i = 0; i < name1.length; i++) letter.add(name1[i]);/*from w w w .ja v a2 s . c o m*/ for (int j = 0; j < name2.length; j++) letter.add(name2[j]); for (int k = 0; k < name3.length; k++) letter.add(name3[k]); System.out.println(letter.size() + " letters must be sent to: " + letter); }
From source file:MyMap.java
public static void main(String[] argv) { // Construct and load the hash. This simulates loading a // database or reading from a file, or wherever the data is. Map map = new MyMap(); // The hash maps from company name to address. // In real life this might map to an Address object... map.put("Adobe", "Mountain View, CA"); map.put("Learning Tree", "Los Angeles, CA"); map.put("IBM", "White Plains, NY"); map.put("Netscape", "Mountain View, CA"); map.put("Microsoft", "Redmond, WA"); map.put("Sun", "Mountain View, CA"); map.put("O'Reilly", "Sebastopol, CA"); // Two versions of the "retrieval" phase. // Version 1: get one pair's value given its key // (presumably the key would really come from user input): String queryString = "O'Reilly"; System.out.println("You asked about " + queryString + "."); String resultString = (String) map.get(queryString); System.out.println("They are located in: " + resultString); System.out.println();/*from w ww. j av a 2 s . c o m*/ // Version 2: get ALL the keys and pairs // (maybe to print a report, or to save to disk) Iterator k = map.keySet().iterator(); while (k.hasNext()) { String key = (String) k.next(); System.out.println("Key " + key + "; Value " + (String) map.get(key)); } // Step 3 - try out the entrySet() method. Set es = map.entrySet(); System.out.println("entrySet() returns " + es.size() + " Map.Entry's"); }