List of usage examples for java.util List stream
default Stream<E> stream()
From source file:de.bund.bfr.knime.pmmlite.core.PmmUtils.java
public static List<String> getIds(List<? extends Identifiable> identifiables) { return identifiables.stream().map(i -> i.getId()).collect(Collectors.toList()); }
From source file:de.monticore.io.paths.IterablePath.java
/** * Creates a new {@link IterablePath} based on the supplied list of {@link File}s containing all * files with the specified extensions. Note: an empty set of extensions will yield an empty * {@link IterablePath}.//from w ww. ja v a 2s . c om * * @param files * @param extensions * @return */ public static IterablePath from(List<File> files, Set<String> extensions) { List<Path> sourcePaths = files.stream().map(file -> file.toPath()).collect(Collectors.toList()); return fromPaths(sourcePaths, extensions); }
From source file:com.formkiq.core.form.FormFinder.java
/** * Find {@link FormJSONField}./*from w ww .j a v a 2 s .c o m*/ * @param archive {@link ArchiveDTO} * @param documentfieldname {@link String} * @return {@link Optional} {@link FormJSONField} */ public static Optional<FormJSONField> findField(final ArchiveDTO archive, final String documentfieldname) { Optional<FormJSONField> op = Optional.empty(); List<WorkflowOutputFormField> fields = stream(archive.getWorkflow()); Optional<WorkflowOutputFormField> o = fields.stream() .filter(s -> s.getDocumentfieldname().equals(documentfieldname)).findFirst(); if (o.isPresent()) { String fuuid = extractLabelAndValue(o.get().getForm()).getRight(); String fid = extractLabelAndValue(o.get().getField()).getRight(); FormJSON form = archive.getForm(fuuid); op = FormFinder.findField(form, NumberUtils.toInt(fid, -1)); } return op; }
From source file:api.wiki.WikiGenerator.java
private static String apiLinksGroupedByApiClass(List<ApiDocumentation> apiDocumentations) throws IOException { return apiDocumentations.stream() .sorted(comparing(apiDocumentation -> apiDocumentation.apiMethod.getDeclaringClass().getName())) .collect(groupingBy(apiDocumentation -> apiDocumentation.apiMethod.getDeclaringClass())).entrySet() .stream().map(entry -> apiClassMethodLinks(entry.getKey(), entry.getValue())) .collect(joining("\n\n")); }
From source file:org.fcrepo.camel.processor.EventProcessor.java
@SuppressWarnings("unchecked") private static Map<String, List<String>> getValuesFromMap(final Map body) { final Map<String, Object> values = (Map<String, Object>) body; final Map<String, List<String>> data = new HashMap<>(); if (values.containsKey("@id")) { data.put(FCREPO_URI, singletonList((String) values.get("@id"))); }/*from w w w . j a v a 2 s. c om*/ if (values.containsKey("id")) { data.putIfAbsent(FCREPO_URI, singletonList((String) values.get("id"))); } if (values.containsKey("@type")) { data.put(FCREPO_RESOURCE_TYPE, (List<String>) values.get("@type")); } if (values.containsKey("type")) { data.putIfAbsent(FCREPO_RESOURCE_TYPE, (List<String>) values.get("type")); } final Map<String, Object> wasGeneratedBy = (Map<String, Object>) values.get("wasGeneratedBy"); if (wasGeneratedBy != null) { if (wasGeneratedBy.containsKey("type")) { data.put(FCREPO_EVENT_TYPE, (List<String>) wasGeneratedBy.get("type")); } data.put(FCREPO_EVENT_ID, singletonList((String) wasGeneratedBy.get("identifier"))); data.put(FCREPO_DATE_TIME, singletonList((String) wasGeneratedBy.get("atTime"))); } final List<Map<String, String>> wasAttributedTo = (List<Map<String, String>>) values.get("wasAttributedTo"); if (wasAttributedTo != null) { data.put(FCREPO_AGENT, wasAttributedTo.stream().map(agent -> agent.get("name")).collect(toList())); } return data; }
From source file:Main.java
public static <T> List<T> innerJoin(List<List<T>> list, BiFunction<T, T, T> function) { if (list == null || function == null) { throw new NullPointerException("list or function must not be null"); }/*from w w w .j a v a 2s .c o m*/ if (list.isEmpty()) { return Collections.emptyList(); } if (list.size() == 1) { return list.get(0); } List<List<T>> result = innerJoin(list.get(0), list.get(1), function); if (list.size() == 2) { return merge(result); } else { for (int i = 2; i < list.size(); i++) { List<T> l1 = list.get(i); List<List<T>> temp = new ArrayList<>(); result.stream().forEach(l -> temp.addAll(innerJoin(l, l1, function))); result = temp; } return merge(result); } }
From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobStatusTransform.java
/** * Enusre that the list contains a date matching Now - the Period. if not add it to the collection *//*from ww w . java 2 s .c om*/ public static void ensureDateFromPeriodExists(List<JobStatusCount> jobStatusCounts, Period period) { //add in the very first date relative to the period if it doesnt exist with a count of 0 if (jobStatusCounts != null && !jobStatusCounts.isEmpty()) { //get the first min date in the result set Date firstDateInResultSet = jobStatusCounts.stream().map(jobStatusCount -> jobStatusCount.getDate()) .min(Date::compareTo).get(); Date firstDate = DateUtils.truncate(DateTimeUtil.getNowUTCTime().minus(period).toDate(), Calendar.DATE); boolean containsFirstDate = jobStatusCounts.stream() .anyMatch(jobStatusCount -> jobStatusCount.getDate().equals(firstDate)); if (!containsFirstDate) { JobStatusCount first = jobStatusCounts.get(0); JobStatusCount min = new JobStatusCountResult(first); min.setDate(firstDate); min.setCount(new Long(0)); jobStatusCounts.add(min); } } }
From source file:Main.java
public static List<String> getDiff(List<String> source, List<String> target) { if (source.size() == 0 || target.size() == 0) { return null; }/* w ww. j ava 2 s . co m*/ if (source == null || target == null) { return null; } int frequency = 1; List<String> max; List<String> min; List<String> diff = new ArrayList<>(); if (source.size() > target.size()) { max = source; min = target; } else { max = target; min = source; } Map<String, Integer> map = new HashMap<>(); max.stream().forEach(s -> map.put(s, frequency)); min.stream().forEach(s -> { if (map.containsKey(s)) { map.put(s, map.get(s) + 1);//rewrite value } else { map.put(s, frequency); } }); //get value=1 map.forEach((k, v) -> { if (v == 1) { diff.add(k); } }); return diff; }
From source file:de.citec.sc.matoll.utils.visualizeSPARQL.java
private static String findRoot(List<List<String>> relations) { String head = ""; Set<String> subj_list = new HashSet<>(); Set<String> obj_list = new HashSet<>(); relations.stream().map((list) -> { subj_list.add(list.get(0));/*from www.j a va 2 s.co m*/ return list; }).forEach((list) -> { obj_list.add(list.get(1)); }); obj_list.removeAll(subj_list); if (obj_list.size() == 1) { return obj_list.toString().replace("[", "").replace("]", ""); } else { return null; } }
From source file:keywhiz.cli.ClientUtils.java
/** * Load cookies from the specified file from JSON to a name to value mapping. * * @param path Location of serialized cookies to load. * @return list of cookies that were read {@link JsonCookie}. * @throws IOException//from w w w .j av a 2 s . co m */ public static List<HttpCookie> loadCookies(Path path) throws IOException { List<HttpCookie> cookieList; try (BufferedReader reader = Files.newBufferedReader(path)) { List<JsonCookie> jsonCookies = Jackson.newObjectMapper().readValue(reader, new TypeReference<List<JsonCookie>>() { }); cookieList = jsonCookies.stream().map(c -> JsonCookie.toHttpCookie(c)).collect(Collectors.toList()); } return cookieList; }