List of usage examples for java.util.stream Collectors toList
public static <T> Collector<T, ?, List<T>> toList()
From source file:fr.jetoile.hadoopunit.HadoopStandaloneBootstrap.java
public static void main(String[] args) throws BootstrapException { try {/*from ww w . j av a 2s . co m*/ configuration = new PropertiesConfiguration("hadoop.properties"); } catch (ConfigurationException e) { throw new BootstrapException("bad config", e); } HadoopBootstrap bootstrap = HadoopBootstrap.INSTANCE; bootstrap.componentsToStart = bootstrap.componentsToStart.stream() .filter(c -> configuration.containsKey(c.getName().toLowerCase()) && configuration.getBoolean(c.getName().toLowerCase())) .collect(Collectors.toList()); bootstrap.componentsToStop = bootstrap.componentsToStop.stream() .filter(c -> configuration.containsKey(c.getName().toLowerCase()) && configuration.getBoolean(c.getName().toLowerCase())) .collect(Collectors.toList()); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { LOGGER.info("All services are going to be stopped"); bootstrap.stopAll(); } }); bootstrap.startAll(); }
From source file:org.neo4j.nlp.examples.wikipedia.main.java
public static void main(String[] args) throws IOException { List<Map<String, Object>> results = getWikipediaArticles(); results = results.stream().filter(a -> !a.get("title").toString().trim().isEmpty()) .collect(Collectors.toList()); //System.out.println(results); // Train model results.forEach(row -> {/* ww w. j a v a 2s . com*/ System.out.println("Training on '" + row.get("title").toString() + "'"); String articleText = getArticleText(row.get("title").toString()); if (articleText != null) { trainOnText(new String[] { (String) articleText }, new String[] { (String) row.get("title") }); } }); //System.out.println(results); // try { // Thread.sleep(10); // } catch (InterruptedException e) { // e.printStackTrace(); // } }
From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java
public static void main(String[] args) throws IOException { Path storeDir = Paths.get(args[0]); try (ProjectUsageStore store = new ProjectUsageStore(storeDir)) { List<ICoReTypeName> types = new ArrayList<>(store.getAllTypes()); types.sort(new TypeNameComparator()); System.out.println(// w w w . j a v a 2 s.c o m types.stream().filter(t -> t.getIdentifier().contains("KaVE.")).collect(Collectors.toList())); // if (args.length == 1 || args[1].equals("countFilteredUsages")) { // countFilteredUsages(types, store); // } else if (args[1].equals("countRecvCallSites")) { // countRecvCallSites(types, store); // } // methodPropabilities(types, store); } }
From source file:com.khartec.waltz.jobs.sample.CapabilityGenerator.java
public static void main(String[] args) throws IOException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class); DSLContext dsl = ctx.getBean(DSLContext.class); List<String> lines = readLines(CapabilityGenerator.class.getResourceAsStream("/capabilities.csv")); System.out.println("Deleting existing Caps's"); dsl.deleteFrom(CAPABILITY).execute(); List<CapabilityRecord> records = lines.stream().skip(1).map(line -> line.split("\t")) .filter(cells -> cells.length == 4).map(cells -> { CapabilityRecord record = new CapabilityRecord(); record.setId(longVal(cells[0])); record.setParentId(longVal(cells[1])); record.setName(cells[2]); record.setDescription(cells[3]); System.out.println(record); return record; }).collect(Collectors.toList()); System.out.println("Inserting new Caps's"); dsl.batchInsert(records).execute();//from w w w . j a v a2 s. c om System.out.println("Done"); }
From source file:com.khartec.waltz.jobs.sample.OrgUnitGenerator.java
public static void main(String[] args) throws IOException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class); DSLContext dsl = ctx.getBean(DSLContext.class); List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/org-units.csv")); System.out.println("Deleting existing OU's"); dsl.deleteFrom(ORGANISATIONAL_UNIT).execute(); List<OrganisationalUnitRecord> records = lines.stream().skip(1) .map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> cells.length == 4) .map(cells -> {/*from w w w. j a v a 2 s. c om*/ OrganisationalUnitRecord record = new OrganisationalUnitRecord(); record.setId(longVal(cells[0])); record.setParentId(longVal(cells[1])); record.setName(cells[2]); record.setDescription(cells[3]); record.setUpdatedAt(new Timestamp(System.currentTimeMillis())); System.out.println(record); return record; }).collect(Collectors.toList()); System.out.println("Inserting new OU's"); dsl.batchInsert(records).execute(); System.out.println("Done"); }
From source file:com.seleniumtests.util.helper.AppTestDocumentation.java
public static void main(String[] args) throws IOException { File srcDir = Paths.get(args[0].replace(File.separator, "/"), "src", "test", "java").toFile(); javadoc = new StringBuilder( "Cette page rfrence l'ensemble des tests et des opration disponible pour l'application\n"); javadoc.append("\n{toc}\n\n"); javadoc.append("${project.summary}\n"); javadoc.append("h1. Tests\n"); try {/* w w w .j av a 2 s. c om*/ Path testsFolders = Files.walk(Paths.get(srcDir.getAbsolutePath())).filter(Files::isDirectory) .filter(p -> p.getFileName().toString().equals("tests")).collect(Collectors.toList()).get(0); exploreTests(testsFolders.toFile()); } catch (IndexOutOfBoundsException e) { throw new ConfigurationException("no 'tests' sub-package found"); } javadoc.append("----"); javadoc.append("h1. Pages\n"); try { Path pagesFolders = Files.walk(Paths.get(srcDir.getAbsolutePath())).filter(Files::isDirectory) .filter(p -> p.getFileName().toString().equals("webpage")).collect(Collectors.toList()).get(0); explorePages(pagesFolders.toFile()); } catch (IndexOutOfBoundsException e) { throw new ConfigurationException("no 'webpage' sub-package found"); } javadoc.append("${project.scmManager}\n"); FileUtils.write(Paths.get(args[0], "src/site/confluence/template.confluence").toFile(), javadoc, Charset.forName("UTF-8")); }
From source file:com.bobby.peng.learning.java.stream.StreamMap.java
public static void main(String[] args) { // List<Integer> list = StreamMap.newRandomList(); ///*from ww w . ja v a 2 s . c o m*/ // List<Integer> list2 = list.stream().map(i->i*5).collect(Collectors.toList()); // // StreamMap.printOut(list2); // // list = list.subList(0,11); // StreamMap.printOut(list); // // String value = "INSERT INTO tech_subao_00.subao_renew_list (id, extra_info, gmt_created, gmt_modified, is_deleted, creator, modifier, remark, status, unqiue_flag, list_biz_id, province_name, province_code, city_name, city_code, license_no, engine_no, frame_no, factory_plate_model, first_register_date, applicant_name, owner_name, owner_certificate_type, owner_id_no, owner_mobile, contact_phone1, contact_phone2, bi_end_date, ci_end_date, vehicle_id, list_allocation_time, booking_start_date, booking_end_date, user_id, renew_batch_id, renew_biz_name, source, organization_id) VALUES (%d, null, '2018-08-07 02:50:36', '2018-08-07 02:50:37', 'N', '', 'system', null, 10, '000000%d', '1', '', '110000', '', '110100', '12312313', '12313', '31231', '111', '2018-05-12', '123', '123', 1, '310111111111111111', '13311111111', '13311111111', '13311111111', '2019-08-07 05:24:56', '2019-08-07 05:25:03', 1, null, null, null, null, %d, 'batch1', 50, 1);"; // // int id = 3; // for(int i=3;i<100;i++) { // for(int j=0;j<2;j++) { // System.out.println(String.format(value,id,id,i)); // id++; // } // } List<Integer> test = new ArrayList<>(); for (int i = 0; i < 1000; i++) { test.add(i); } test.parallelStream().map(i -> { System.out.println(i); return i; }).collect(Collectors.toList()); System.out.println("==================================="); test.stream().map(i -> { System.out.println(i); return i; }).collect(Collectors.toList()); }
From source file:com.cloudera.oryx.app.traffic.TrafficUtil.java
public static void main(String[] args) throws Exception { if (args.length < 3) { System.err.println("usage: TrafficUtil [hosts] [requestIntervalMS] [threads] [... other args]"); return;/*from w ww .j a va 2s .c o m*/ } String[] hostStrings = COMMA.split(args[0]); Preconditions.checkArgument(hostStrings.length >= 1); int requestIntervalMS = Integer.parseInt(args[1]); Preconditions.checkArgument(requestIntervalMS >= 0); int numThreads = Integer.parseInt(args[2]); Preconditions.checkArgument(numThreads >= 1); String[] otherArgs = new String[args.length - 3]; System.arraycopy(args, 3, otherArgs, 0, otherArgs.length); List<URI> hosts = Arrays.stream(hostStrings).map(URI::create).collect(Collectors.toList()); int perClientRequestIntervalMS = numThreads * requestIntervalMS; Endpoints alsEndpoints = new Endpoints(ALSEndpoint.buildALSEndpoints()); AtomicLong requestCount = new AtomicLong(); AtomicLong serverErrorCount = new AtomicLong(); AtomicLong clientErrorCount = new AtomicLong(); AtomicLong exceptionCount = new AtomicLong(); long start = System.currentTimeMillis(); ExecUtils.doInParallel(numThreads, numThreads, true, i -> { RandomGenerator random = RandomManager.getRandom(Integer.toString(i).hashCode() ^ System.nanoTime()); ExponentialDistribution msBetweenRequests; if (perClientRequestIntervalMS > 0) { msBetweenRequests = new ExponentialDistribution(random, perClientRequestIntervalMS); } else { msBetweenRequests = null; } ClientConfig clientConfig = new ClientConfig(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(numThreads); connectionManager.setDefaultMaxPerRoute(numThreads); clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager); clientConfig.connectorProvider(new ApacheConnectorProvider()); Client client = ClientBuilder.newClient(clientConfig); try { while (true) { try { WebTarget target = client.target("http://" + hosts.get(random.nextInt(hosts.size()))); Endpoint endpoint = alsEndpoints.chooseEndpoint(random); Invocation invocation = endpoint.makeInvocation(target, otherArgs, random); long startTime = System.currentTimeMillis(); Response response = invocation.invoke(); try { response.readEntity(String.class); } finally { response.close(); } long elapsedMS = System.currentTimeMillis() - startTime; int statusCode = response.getStatusInfo().getStatusCode(); if (statusCode >= 400) { if (statusCode >= 500) { serverErrorCount.incrementAndGet(); } else { clientErrorCount.incrementAndGet(); } } endpoint.recordTiming(elapsedMS); if (requestCount.incrementAndGet() % 10000 == 0) { long elapsed = System.currentTimeMillis() - start; log.info("{}ms:\t{} requests\t({} client errors\t{} server errors\t{} exceptions)", elapsed, requestCount.get(), clientErrorCount.get(), serverErrorCount.get(), exceptionCount.get()); for (Endpoint e : alsEndpoints.getEndpoints()) { log.info("{}", e); } } if (msBetweenRequests != null) { int desiredElapsedMS = (int) Math.round(msBetweenRequests.sample()); if (elapsedMS < desiredElapsedMS) { Thread.sleep(desiredElapsedMS - elapsedMS); } } } catch (Exception e) { exceptionCount.incrementAndGet(); log.warn("{}", e.getMessage()); } } } finally { client.close(); } }); }
From source file:io.fabric8.vertx.maven.plugin.FileFilterMain.java
public static void main(String[] args) { Commandline commandline = new Commandline(); commandline.setExecutable("java"); commandline.createArg().setValue("io.vertx.core.Launcher"); commandline.createArg().setValue("--redeploy=target/**/*"); System.out.println(commandline);/*from w ww. j ava 2 s . co m*/ File baseDir = new File("/Users/kameshs/git/fabric8io/vertx-maven-plugin/samples/vertx-demo"); List<String> includes = new ArrayList<>(); includes.add("src/**/*.java"); //FileAlterationMonitor monitor = null; try { Set<Path> inclDirs = new HashSet<>(); includes.forEach(s -> { try { if (s.startsWith("**")) { Path rootPath = Paths.get(baseDir.toString()); if (Files.exists(rootPath)) { File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory()); Objects.requireNonNull(dirs); Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString()))); } } else if (s.contains("**")) { String root = s.substring(0, s.indexOf("/**")); Path rootPath = Paths.get(baseDir.toString(), root); if (Files.exists(rootPath)) { File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory()); Objects.requireNonNull(dirs); Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString()))); } } List<Path> dirs = FileUtils.getFileAndDirectoryNames(baseDir, s, null, true, true, true, true) .stream().map(FileUtils::dirname).map(Paths::get) .filter(p -> Files.exists(p) && Files.isDirectory(p)).collect(Collectors.toList()); inclDirs.addAll(dirs); } catch (Exception e) { e.printStackTrace(); } }); FileAlterationMonitor monitor = fileWatcher(inclDirs); Runnable monitorTask = () -> { try { monitor.start(); } catch (Exception e) { e.printStackTrace(); } }; monitorTask.run(); } catch (Exception e) { e.printStackTrace(); } }
From source file:io.reactiverse.vertx.maven.plugin.FileFilterMain.java
public static void main(String[] args) { Commandline commandline = new Commandline(); commandline.setExecutable("java"); commandline.createArg().setValue("io.vertx.core.Launcher"); commandline.createArg().setValue("--redeploy=target/**/*"); System.out.println(commandline);/*from w ww .ja v a 2 s .c om*/ File baseDir = new File("/Users/kameshs/git/reactiverse/vertx-maven-plugin/samples/vertx-demo"); List<String> includes = new ArrayList<>(); includes.add("src/**/*.java"); //FileAlterationMonitor monitor = null; try { Set<Path> inclDirs = new HashSet<>(); includes.forEach(s -> { try { if (s.startsWith("**")) { Path rootPath = Paths.get(baseDir.toString()); if (Files.exists(rootPath)) { File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory()); Objects.requireNonNull(dirs); Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString()))); } } else if (s.contains("**")) { String root = s.substring(0, s.indexOf("/**")); Path rootPath = Paths.get(baseDir.toString(), root); if (Files.exists(rootPath)) { File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory()); Objects.requireNonNull(dirs); Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString()))); } } List<Path> dirs = FileUtils.getFileAndDirectoryNames(baseDir, s, null, true, true, true, true) .stream().map(FileUtils::dirname).map(Paths::get) .filter(p -> Files.exists(p) && Files.isDirectory(p)).collect(Collectors.toList()); inclDirs.addAll(dirs); } catch (Exception e) { e.printStackTrace(); } }); FileAlterationMonitor monitor = fileWatcher(inclDirs); Runnable monitorTask = () -> { try { monitor.start(); } catch (Exception e) { e.printStackTrace(); } }; monitorTask.run(); } catch (Exception e) { e.printStackTrace(); } }