List of usage examples for java.util Set forEach
default void forEach(Consumer<? super T> action)
From source file:Main.java
public static void main(String[] args) { // collect as typed array Stream<String> words = Stream.of("All", "men", "are", "created", "equal"); Set<String> wordsSet = words.collect(Collectors.toSet()); wordsSet.forEach(n -> System.out.println(n)); }
From source file:Main.java
public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put("CSS", "style"); map.put("HTML", "mark up"); map.put("Oracle", "database"); map.put("XML", "data"); // Get the entry Set Set<Map.Entry<String, String>> entries = map.entrySet(); entries.forEach((Map.Entry<String, String> entry) -> { String key = entry.getKey(); String value = entry.getValue(); System.out.println("key=" + key + ", value=" + value); });//from w ww . j a v a 2 s .co m }
From source file:Main.java
public static void main(String[] args) { // collect as typed array Stream<String> words = Stream.of("All", "men", "are", "created", "equal"); Set<String> wordsSet = words.collect(Collectors.toCollection(TreeSet::new)); wordsSet.forEach(n -> System.out.println(n)); }
From source file:org.eclipse.che.util.GwtXmlGenerator.java
/** * Generated consolidated gwt.xml based on exists XX.gwt.xml in class path * * @param args// ww w . java 2 s . c o m * possible arguments * --rootDir - directory where gwt.xml file will be generated, default "." * --gwtFileName - Name of the generated file in rootDir, default "org/eclipse/che/ide/IDE.gwt.xml" * --entryPoint - gwt xml entry point, default "org.eclipse.che.ide.client.IDE" * --styleSheet - gwt xml stylesheet, default "IDE.css" * --loggingEnabled - Enable or disable gwt logging, default "false" * --includePackages - Include only specific packages where *.gwt.xml can be found, default "No value. Means all packages" * --excludePackages - Exclude packages from *.gwt.xml scanning , default "com.google", "elemental","java.util","java.lang" */ public static void main(String[] args) { try { System.out.println(" ------------------------------------------------------------------------ "); System.out.println("Searching for GWT"); System.out.println(" ------------------------------------------------------------------------ "); Map<String, Set<String>> parsedArgs = GeneratorUtils.parseArgs(args); GwtXmlModuleSearcher searcher = new GwtXmlModuleSearcher( parsedArgs.getOrDefault("excludePackages", ImmutableSet.of("com.google", "elemental", "java.util", "java.lang")), parsedArgs.getOrDefault("includePackages", Collections.emptySet()), Collections.emptySet()); Set<String> gwtModules = searcher.getGwtModulesFromClassPath(); gwtModules.forEach(System.out::println); System.out.println("Found " + gwtModules.size() + " gwt modules"); GwtXmlGeneratorConfig gwtXmlGeneratorConfig = new GwtXmlGeneratorConfig(gwtModules, new File(getSingleValueOrDefault(parsedArgs, "rootDir", ".")), getSingleValueOrDefault(parsedArgs, "gwtFileName", DEFAULT_GWT_XML_PATH), getSingleValueOrDefault(parsedArgs, "entryPoint", DEFAULT_GWT_ETNRY_POINT), getSingleValueOrDefault(parsedArgs, "styleSheet", DEFAULT_STYLE_SHEET), parseBoolean( getSingleValueOrDefault(parsedArgs, "loggingEnabled", DEFAULT_LOGGING.toString()))); GwtXmlGenerator gwtXmlGenerator = new GwtXmlGenerator(gwtXmlGeneratorConfig); gwtXmlGenerator.generateGwtXml(); } catch (IOException e) { System.err.println(e.getMessage()); // error System.exit(1);//NOSONAR } }
From source file:org.ado.picasa.Main.java
public static void main(String[] args) throws Exception { final Options options = new Options(); options.addOption(new Option("a", "album", true, "Album name")); options.addOption("v", "verification-code", true, "Verification code"); options.addOption("o", "output", true, "Albums output directory"); options.addOption("h", "help", false, "Prints this help"); final CommandLine cmd = new DefaultParser().parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("picasa-crawler", options); System.exit(0);//from ww w. ja va 2 s.c o m } validateEnvironmentVariables(); final File outputDirectory; if (cmd.hasOption("o")) { outputDirectory = new File(cmd.getOptionValue("o")); } else { outputDirectory = DEFAULT_OUTPUT_DIR; } FileUtils.forceMkdir(outputDirectory); long start = System.currentTimeMillis(); final FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.dir", outputDirectory.getAbsolutePath()); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "image/jpeg,image/png"); final FirefoxDriver driver = new FirefoxDriver(profile); loginIntoPicasa(cmd.getOptionValue("v"), driver); driver.navigate().to("https://picasaweb.google.com/home?showall=true"); TimeUnit.SECONDS.sleep(2); final List<WebElement> albumLinks = driver .findElements(By.xpath("//p[@class='gphoto-album-cover-title']/a")); if (cmd.hasOption("a")) { final String albumName = cmd.getOptionValue("a").trim(); System.out.println(String.format("Album: %s", albumName)); downloadAlbum(driver, albumLinks.stream().filter(al -> al.getText().equals(albumName)).findFirst().get() .getAttribute("href"), outputDirectory); } else { final Set<String> albumHrefs = albumLinks.stream().map(a -> a.getAttribute("href")) .collect(Collectors.toSet()); albumHrefs.forEach(a -> downloadAlbum(driver, a, outputDirectory)); } TimeUnit.SECONDS.sleep(10); System.out.println("done"); long end = System.currentTimeMillis(); System.out.println(String.format("execution took %d minutes.", Math.min(TimeUnit.MILLISECONDS.toMinutes(end - start), 1))); driver.close(); }
From source file:GoogleImages.java
public static void main(String[] args) throws InterruptedException { String searchTerm = "s woman"; // term to search for (use spaces to separate terms) int offset = 40; // we can only 20 results at a time - use this to offset and get more! String fileSize = "50mp"; // specify file size in mexapixels (S/M/L not figured out yet) String source = null; // string to save raw HTML source code // format spaces in URL to avoid problems searchTerm = searchTerm.replaceAll(" ", "%20"); // get Google image search HTML source code; mostly built from PhyloWidget example: // http://code.google.com/p/phylowidget/source/browse/trunk/PhyloWidget/src/org/phylowidget/render/images/ImageSearcher.java int offset2 = 0; Set urlsss = new HashSet<String>(); while (offset2 < 600) { try {/*from ww w .java 2s . co m*/ URL query = new URL("https://www.google.ru/search?start=" + offset2 + "&q=angry+woman&newwindow=1&client=opera&hs=bPE&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiAgcKozIfNAhWoHJoKHSb_AUoQ_AUIBygB&biw=1517&bih=731&dpr=0.9#imgrc=G_1tH3YOPcc8KM%3A"); HttpURLConnection urlc = (HttpURLConnection) query.openConnection(); // start connection... urlc.setInstanceFollowRedirects(true); urlc.setRequestProperty("User-Agent", ""); urlc.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); // stream in HTTP source to file StringBuffer response = new StringBuffer(); char[] buffer = new char[1024]; while (true) { int charsRead = in.read(buffer); if (charsRead == -1) { break; } response.append(buffer, 0, charsRead); } in.close(); // close input stream (also closes network connection) source = response.toString(); } // any problems connecting? let us know catch (Exception e) { e.printStackTrace(); } // print full source code (for debugging) // println(source); // extract image URLs only, starting with 'imgurl' if (source != null) { // System.out.println(source); int c = StringUtils.countMatches(source, "http://www.vmir.su"); System.out.println(c); int index = source.indexOf("src="); System.out.println(source.subSequence(index, index + 200)); while (index >= 0) { System.out.println(index); index = source.indexOf("src=", index + 1); if (index == -1) { break; } String rr = source.substring(index, index + 200 > source.length() ? source.length() : index + 200); if (rr.contains("\"")) { rr = rr.substring(5, rr.indexOf("\"", 5)); } System.out.println(rr); urlsss.add(rr); } } offset2 += 20; Thread.sleep(1000); System.out.println("off set = " + offset2); } System.out.println(urlsss); urlsss.forEach(new Consumer<String>() { public void accept(String s) { try { saveImage(s, "C:\\Users\\Java\\Desktop\\ang\\" + UUID.randomUUID().toString() + ".jpg"); } catch (IOException ex) { Logger.getLogger(GoogleImages.class.getName()).log(Level.SEVERE, null, ex); } } }); // String[][] m = matchAll(source, "img height=\"\\d+\" src=\"([^\"]+)\""); // older regex, no longer working but left for posterity // built partially from: http://www.mkyong.com/regular-expressions/how-to-validate-image-file-extension-with-regular-expression // String[][] m = matchAll(source, "imgurl=(.*?\\.(?i)(jpg|jpeg|png|gif|bmp|tif|tiff))"); // (?i) means case-insensitive // for (int i = 0; i < m.length; i++) { // iterate all results of the match // println(i + ":\t" + m[i][1]); // print (or store them)** // } }
From source file:Main.java
public static void listKeys(Map<String, String> map) { System.out.println("Key Set:"); Set<String> keys = map.keySet(); keys.forEach(System.out::println); System.out.println();//from w ww. j a v a2 s . c o m }
From source file:Main.java
public static void listEntries(Map<String, String> map) { System.out.println("Entry Set:"); // Get the entry Set Set<Map.Entry<String, String>> entries = map.entrySet(); entries.forEach((Map.Entry<String, String> entry) -> { String key = entry.getKey(); String value = entry.getValue(); System.out.println("key=" + key + ", value=" + value); });// ww w . j ava 2 s. com }
From source file:Main.java
public static <T> Set<T> clone(Set<T> set) { Set<T> newSet = new HashSet<>(); set.forEach(newSet::add); return newSet; }
From source file:com.github.ljtfreitas.restify.spring.configure.RestifyableTypeScanner.java
public static RestifyableTypeScanner excluding(Set<TypeFilter> filters) { RestifyableTypeScanner scanner = new RestifyableTypeScanner(); filters.forEach(f -> scanner.addExcludeFilter(f)); return scanner; }