List of usage examples for java.util List forEach
default void forEach(Consumer<? super T> action)
From source file:com.taobao.android.builder.tools.bundleinfo.BundleGraphExecutor.java
public static void execute(List<BundleInfo> bundleInfos, int parableCount, BundleItemRunner bundleItemRunner) throws IOException, InterruptedException { Map<String, BundleInfo> bundleInfoMap = new HashMap<>(); bundleInfos.forEach(new Consumer<BundleInfo>() { @Override// www. j a va 2 s.co m public void accept(BundleInfo bundleInfo) { bundleInfoMap.put(bundleInfo.getPkgName(), bundleInfo); } }); Map<String, BundleItem> bundleItemMap = getBundleItemMap(bundleInfoMap); handleCircleDependency(bundleItemMap); int size = bundleItemMap.size(); ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("bundleGraph", logger, parableCount); int index = 0; int j = 0; while (index <= size) { List<String> keys = new ArrayList<>(); List<Runnable> runnables = new ArrayList<>(); for (String key : bundleItemMap.keySet()) { //System.out.println("test" + key); BundleItem bundleItem = bundleItemMap.get(key); if (bundleItem.canResolve()) { index++; //bundleItem.resolve(); keys.add(key); final String name = index + bundleItem.bundleInfo.getPkgName(); runnables.add(new Runnable() { @Override public void run() { logger.warn("start to do bundle proguard for " + name); bundleItemRunner.execute(bundleItem); logger.warn("end do bundle proguard for " + name); } }); } } Profiler.enter("execute stage " + j++ + " runnables " + runnables.size()); executorServicesHelper.execute(runnables); Profiler.release(); if (keys.isEmpty()) { break; } for (String key : keys) { bundleItemMap.get(key).resolve(); bundleItemMap.remove(key); } } if (index != size) { throw new GradleException("bundleGraph is some thing wrong"); } }
From source file:com.baidu.rigel.biplatform.tesseract.util.DataModelBuilder.java
/** * tailHeadFields?headFields???headField??? * /*from w w w . j av a2 s .c o m*/ * @param headFields ? * @param tailFields ??? */ private static void addTailFields(List<HeadField> headFields, List<HeadField> tailFields) { if (CollectionUtils.isNotEmpty(headFields)) { if (CollectionUtils.isNotEmpty(tailFields)) { headFields.forEach((node) -> { List<HeadField> leafNodes = node.getLeafFileds(true); for (HeadField leaf : leafNodes) { // ????? leaf.getNodeList() .addAll(packageParentLevelField(DeepcopyUtils.deepCopy(tailFields), leaf)); } }); } } else { headFields.addAll(tailFields); } }
From source file:oct.util.Util.java
public static List<LinePoint> findMaxAndMins(List<LinePoint> line) { //create list of all positive Y values to get peaks ArrayList<LinePoint> convList = new ArrayList<>(line.size()); line.forEach(p -> { convList.add(new LinePoint(p.getX(), Math.abs(p.getY()))); });//from w w w.jav a 2 s . c o m //find X values of peaks List<LinePoint> peaks = getMaximums(convList); //collect peak points List<LinePoint> ret = line.parallelStream() .filter(p -> peaks.stream().anyMatch(pk -> pk.getX() == p.getX())).collect(Collectors.toList()); //sort by X position ret.sort(Comparator.comparingInt(peak -> peak.getX())); return ret; }
From source file:de.fosd.jdime.Main.java
/** * Merges the input files./* w w w. ja v a 2s .c o m*/ * * @param context * merge context */ public static void merge(MergeContext context) { List<FileArtifact> inFiles = context.getInputFiles(); FileArtifact outFile = context.getOutputFile(); if (context.isFilterInputDirectories()) { inFiles.forEach(FileArtifact::filterNonJavaFiles); } boolean conditional = context.isConditionalMerge(); MergeOperation<FileArtifact> merge = new MergeOperation<>(inFiles, outFile, conditional); merge.apply(context); }
From source file:dk.dma.ais.abnormal.analyzer.AbnormalAnalyzerAppModule.java
/** * Initialize internal data structures required to accept/reject track updates based on black list mechanism. * @param configuration//from w ww . ja va2 s . c o m * @return */ private static int[] initVesselBlackList(Configuration configuration) { ArrayList<Integer> blacklistedMmsis = new ArrayList<>(); try { List blacklistedMmsisConfig = configuration.getList("blacklist.mmsi"); blacklistedMmsisConfig.forEach(blacklistedMmsi -> { try { Integer blacklistedMmsiBoxed = Integer.valueOf(blacklistedMmsi.toString()); if (blacklistedMmsiBoxed > 0 && blacklistedMmsiBoxed < 1000000000) { blacklistedMmsis.add(blacklistedMmsiBoxed); } else if (blacklistedMmsiBoxed != -1) { LOG.warn("Black listed MMSI no. out of range: " + blacklistedMmsiBoxed + "."); } } catch (NumberFormatException e) { LOG.warn("Black listed MMSI no. \"" + blacklistedMmsi + "\" cannot be cast to integer."); } }); } catch (ConversionException e) { LOG.warn(e.getMessage(), e); } if (blacklistedMmsis.size() > 0) { LOG.info("The following " + blacklistedMmsis.size() + " MMSI numbers are black listed and will not be tracked."); LOG.info(Arrays.toString(blacklistedMmsis.toArray())); } int[] array = new int[blacklistedMmsis.size()]; for (int i = 0; i < blacklistedMmsis.size(); i++) { array[i] = blacklistedMmsis.get(i); } return array; }
From source file:com.baidu.rigel.biplatform.tesseract.util.QueryRequestUtil.java
public static SearchIndexResultSet processGroupBy(SearchIndexResultSet dataSet, QueryRequest query, QueryContext queryContext) throws NoSuchFieldException { List<SearchIndexResultRecord> transList = null; long current = System.currentTimeMillis(); Map<String, Map<String, Set<String>>> leafValueMap = QueryRequestUtil.transQueryRequest2LeafMap(query); Map<String, String> allDimVal = collectAllMem(queryContext); LOGGER.info("cost :" + (System.currentTimeMillis() - current) + " to collect leaf map."); current = System.currentTimeMillis(); List<String> groupList = Lists.newArrayList(query.getGroupBy().getGroups()); List<QueryMeasure> queryMeasures = query.getSelect().getQueryMeasures(); // count?sum//from w ww.j ava 2s . c o m queryMeasures.forEach(measure -> { if (measure.getAggregator().equals(Aggregator.COUNT)) { measure.setAggregator(Aggregator.SUM); } }); Meta meta = dataSet.getMeta(); int dimSize = query.getSelect().getQueryProperties().size(); if (dataSet != null && dataSet.size() != 0 && dataSet instanceof SearchIndexResultSet) { transList = dataSet.getDataList(); if (MapUtils.isNotEmpty(leafValueMap)) { // ??? List<SearchIndexResultRecord> copyLeafRecords = new ArrayList<SearchIndexResultRecord>(); transList.forEach(record -> { leafValueMap.forEach((prop, valueMap) -> { try { String currValue = record.getField(meta.getFieldIndex(prop)) != null ? record.getField(meta.getFieldIndex(prop)).toString() : null; Set<String> valueSet = leafValueMap.get(prop).get(currValue); if (valueSet != null) { int i = 0; for (String value : valueSet) { if (i > 0) { // ? SearchIndexResultRecord newRec = DeepcopyUtils.deepCopy(record); newRec.setField(meta.getFieldIndex(prop), value); generateGroupBy(newRec, groupList, meta); copyLeafRecords.add(newRec); } else { record.setField(meta.getFieldIndex(prop), value); generateGroupBy(record, groupList, meta); } i++; } } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }); }); if (CollectionUtils.isNotEmpty(copyLeafRecords)) { // ?? transList.addAll(copyLeafRecords); } transList = AggregateCompute.aggregate(transList, dimSize, queryMeasures); } } else { return dataSet; } LOGGER.info("cost :" + (System.currentTimeMillis() - current) + " to map leaf."); current = System.currentTimeMillis(); if (CollectionUtils.isEmpty(queryMeasures)) { dataSet.setDataList(AggregateCompute.distinct(transList)); return dataSet; } if (MapUtils.isNotEmpty(allDimVal)) { // List<ResultRecord> preResultList = DeepcopyUtils.deepCopy(transList); for (String properties : allDimVal.keySet()) { LinkedList<SearchIndexResultRecord> summaryCalcList = new LinkedList<SearchIndexResultRecord>(); for (SearchIndexResultRecord record : transList) { SearchIndexResultRecord vRecord = DeepcopyUtils.deepCopy(record); vRecord.setField(meta.getFieldIndex(properties), allDimVal.get(properties)); // generateGroupBy(vRecord, groupList); vRecord.setGroupBy(allDimVal.get(properties)); summaryCalcList.add(vRecord); } transList.addAll(AggregateCompute.aggregate(summaryCalcList, dimSize, queryMeasures)); } } dataSet.setDataList(transList); LOGGER.info("cost :" + (System.currentTimeMillis() - current) + " aggregator leaf."); return dataSet; }
From source file:fi.hsl.parkandride.core.service.PredictionServiceTest.java
private static void inParallel(Runnable... commands) throws InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(commands.length); List<Future<?>> futures = Stream.of(commands).map(executor::submit).collect(toList()); List<Exception> exceptions = futures.stream().flatMap(future -> { try {/*from ww w .j ava2 s . co m*/ future.get(); return Stream.empty(); } catch (Exception e) { return Stream.of(e); } }).collect(toList()); if (!exceptions.isEmpty()) { AssertionError e = new AssertionError( "There were " + exceptions.size() + " uncaught exceptions in the background threads"); exceptions.forEach(e::addSuppressed); throw e; } }
From source file:com.validation.manager.core.tool.Tool.java
public static File createZipFile(List<File> files, String zipName) throws FileNotFoundException, IOException { if (!zipName.endsWith(".zip")) { zipName += ".zip"; }//from w ww.j a va 2 s.c om File f = new File(zipName); if (f.getParentFile() != null) { f.getParentFile().mkdirs(); } try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f))) { files.forEach(file -> { try { ZipEntry ze = new ZipEntry(file.getName()); out.putNextEntry(ze); byte[] data = FileUtils.readFileToByteArray(file); out.write(data, 0, data.length); out.closeEntry(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }); } return f; }
From source file:oct.util.Util.java
public static List<LinePoint> findPeaksAndVallies(List<LinePoint> line) { //first find peaks List<LinePoint> peaks = getMaximums(line); //create inverse of line to find vallies ArrayList<LinePoint> convList = new ArrayList<>(line.size()); line.forEach(p -> { convList.add(new LinePoint(p.getX(), 0D - p.getY())); });/*from w w w .j a v a 2 s .com*/ //find X values of vallies List<LinePoint> vallies = getMaximums(convList); //collect valley points List<LinePoint> ret = line.parallelStream() .filter(p -> vallies.stream().anyMatch(pk -> pk.getX() == p.getX())).collect(Collectors.toList()); //sort by X position ret.addAll(peaks); ret.sort(Comparator.comparingInt(peak -> peak.getX())); return ret; }
From source file:ai.susi.mind.SusiSkill.java
/** * if no keys are given, we compute them from the given phrases * @param phrases// w w w . j a v a2s. c om * @return */ private static JSONArray computeKeysFromPhrases(List<SusiPhrase> phrases) { Set<String> t = new LinkedHashSet<>(); // create a list of token sets from the phrases List<Set<String>> ptl = new ArrayList<>(); final AtomicBoolean needsCatchall = new AtomicBoolean(false); phrases.forEach(phrase -> { Set<String> s = new HashSet<>(); for (String token : SPACE_PATTERN.split(phrase.getPattern().toString())) { String m = SusiPhrase.extractMeat(token.toLowerCase()); if (m.length() > 1) s.add(m); } // if there is no meat inside, it will not be possible to access the skill without the catchall skill, so remember that if (s.size() == 0) needsCatchall.set(true); ptl.add(s); }); // this is a kind of emergency case where we need a catchall skill because otherwise we cannot access one of the phrases JSONArray a = new JSONArray(); if (needsCatchall.get()) return a.put(CATCHALL_KEY); // collect all token ptl.forEach(set -> set.forEach(token -> t.add(token))); // if no tokens are available, return the catchall key if (t.size() == 0) return a.put(CATCHALL_KEY); // make a copy to make it possible to use the original key set again Set<String> tc = new LinkedHashSet<>(); t.forEach(c -> tc.add(c)); // remove all token that do not appear in all phrases ptl.forEach(set -> { Iterator<String> i = t.iterator(); while (i.hasNext()) if (!set.contains(i.next())) i.remove(); }); // if no token is left, use the original tc set and add all keys if (t.size() == 0) { tc.forEach(c -> a.put(c)); return a; } // use only the first token, because that appears in all the phrases return new JSONArray().put(t.iterator().next()); }