Java Code Examples for java.util.List.stream()

The following are Jave code examples for showing how to use stream() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: com-liferay-apio-architect   File: WebSiteServiceImpl.java   View Source Code Vote up 6 votes
@Override
public PageItems<WebSite> getPageItems(
	Pagination pagination, long companyId) {

	List<Group> groups = _groupLocalService.getGroups(companyId, 0, true);

	List<Group> paginationGroups = ListUtil.subList(
		groups, pagination.getStartPosition(), pagination.getEndPosition());

	Stream<Group> stream = paginationGroups.stream();

	List<WebSite> webSites = stream.map(
		WebSiteImpl::new
	).collect(
		Collectors.toList()
	);

	int count = _groupLocalService.getGroupsCount(companyId, 0, true);

	return new PageItems<>(webSites, count);
}
 
Example 2
Project: matchmaker   File: MultiMatcherMatchFunctions.java   View Source Code Vote up 6 votes
private static <R> Stream<Matcher<R>> potentialMatchersInOrder(
        List<Matcher<R>> cases,
        SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> matchersByScopeType,
        Object object
) {
    if (object == null) {
        return cases.stream();
    } else {
        Stream<Class<?>> supertypes = Util.supertypes(object.getClass());
        TreeSet<Indexed<Matcher<R>>> indexedMatchersInOrder = supertypes
                .flatMap(type -> matchersByScopeType.get(type).stream())
                .collect(toCollection(TreeSet::new));
        return indexedMatchersInOrder.stream()
                .map(Indexed::value);
    }
}
 
Example 3
Project: limberest-demo   File: MoviesPersistFile.java   View Source Code Vote up 6 votes
@Override
public List<Movie> retrieve(Query query) throws PersistException {
    List<Movie> movies = getMovies();
    Stream<Movie> stream = movies.stream();
    
    // filter
    if (query.hasFilters() || query.getSearch() != null) {
        stream = stream.filter(movie -> query.match(new JsonMatcher(movie.toJson())));
    }
    
    // sort
    if ((query.getSort() != null && !"title".equals(query.getSort())) || query.isDescending()) {
        stream = stream.sorted(new JsonableComparator(query, (j1, j2) -> {
            return getSortTitle(j1).compareToIgnoreCase(getSortTitle(j2));
        }));
    }
    
    // paginate
    if (query.getStart() > 0)
        stream = stream.skip(query.getStart());
    if (query.getMax() != Query.MAX_ALL)
        stream = stream.limit(query.getMax());
    
    return stream.collect(Collectors.toList());
}
 
Example 4
Project: smart-testing   File: TagsParser.java   View Source Code Vote up 5 votes
private Stream<String> retrieveTagFromAnnotation(Annotation tagsAnnotation) {
    final List<String> tags = new ArrayList<>();
    if (TAG.equals(tagsAnnotation.annotationType().getName())) {
        final String tagName = getTagName(tagsAnnotation);
        if (tagName != null) {
            tags.add(tagName);
        }
    } else {
        tags.addAll(getMultipleTagNames(tagsAnnotation));
    }
    return tags.stream();
}
 
Example 5
Project: bamboo-soy   File: TemplateNameUtils.java   View Source Code Vote up 5 votes
public Stream<String> denormalizeIdentifier(String identifier) {
  if (!namespaceMatcher.asPredicate().test(identifier)) {
    return Stream.of(identifier);
  }

  List<String> identifiers = new ArrayList<>();
  identifiers.add(identifier);
  for (Map.Entry<String, String> entry : namespaceToAlias.entrySet()) {
    if (identifier.startsWith(entry.getKey())) {
      identifiers.add(identifier.replace(entry.getKey(), entry.getValue()));
    }
  }
  return identifiers.stream();
}
 
Example 6
Project: highfrequencyrobots   File: DataCoderTest.java   View Source Code Vote up 5 votes
private static Stream<Double> getSparsityTestLoop() {
  List<Double> sparsity = new ArrayList<>();
  for(nonsparse = 0.02; nonsparse <= 1.0; nonsparse += 0.02) {
    sparsity.add(nonsparse);
  }
  return sparsity.stream();
}
 
Example 7
Project: openjdk-jdk10   File: ModuleLayer.java   View Source Code Vote up 5 votes
/**
 * Returns a stream of the layers that have at least one module defined to
 * the given class loader.
 */
static Stream<ModuleLayer> layers(ClassLoader loader) {
    List<ModuleLayer> list = CLV.get(loader);
    if (list != null) {
        return list.stream();
    } else {
        return Stream.empty();
    }
}
 
Example 8
Project: openjdk-jdk10   File: ImagePluginStack.java   View Source Code Vote up 5 votes
@Override
public Stream<ResourcePoolEntry> entries() {
    List<ResourcePoolEntry> lst = new ArrayList<>();
    module.entries().forEach(md -> {
        lst.add(getUncompressed(md));
    });
    return lst.stream();
}
 
Example 9
Project: allure-java   File: AllureSpock.java   View Source Code Vote up 5 votes
private <T extends Annotation> Stream<Label> getLabels(final IterationInfo iterationInfo, final Class<T> clazz,
                                                       final Function<T, Label> extractor) {
    final List<Label> onFeature = getFeatureAnnotations(iterationInfo, clazz).stream()
            .map(extractor)
            .collect(Collectors.toList());
    if (!onFeature.isEmpty()) {
        return onFeature.stream();
    }
    return getSpecAnnotations(iterationInfo, clazz).stream()
            .map(extractor);
}
 
Example 10
Project: allure-java   File: AllureJunit4.java   View Source Code Vote up 5 votes
private <T extends Annotation> Stream<Label> getLabels(final Description result, final Class<T> labelAnnotation,
                                                       final Function<T, Label> extractor) {

    final List<Label> labels = getAnnotationsOnMethod(result, labelAnnotation).stream()
            .map(extractor)
            .collect(Collectors.toList());

    if (labelAnnotation.isAnnotationPresent(Repeatable.class) || labels.isEmpty()) {
        final Stream<Label> onClassLabels = getAnnotationsOnClass(result, labelAnnotation).stream()
                .map(extractor);
        labels.addAll(onClassLabels.collect(Collectors.toList()));
    }

    return labels.stream();
}
 
Example 11
Project: koryphe   File: TupleAndExample.java   View Source Code Vote up 5 votes
@Override
public Stream<Tuple<String>> getInput() {
    List<Tuple<String>> inputTuples = Arrays.asList(
            createMapTuple(1, 2, 3),
            createMapTuple(4, 5, 6),
            createMapTuple(7, 8, 9));
    return inputTuples.stream();
}
 
Example 12
Project: koryphe   File: TupleDivideByExample.java   View Source Code Vote up 5 votes
@Override
public Stream<Tuple<String>> getInput() {
    List<Tuple<String>> inputTuples = Arrays.asList(
            createMapTuple(1, 2, 3),
            createMapTuple(4, 5, 6),
            createMapTuple(7, 8, 9));
    return inputTuples.stream();
}
 
Example 13
Project: koryphe   File: TupleAggregationProductExample.java   View Source Code Vote up 5 votes
@Override
public Stream<Tuple<String>> getInput() {
    List<Tuple<String>> inputTuples = Arrays.asList(
            createMapTuple(1, 2, 3),
            createMapTuple(4, 5, 6),
            createMapTuple(7, 8, 9));
    return inputTuples.stream();
}
 
Example 14
Project: koryphe   File: TupleMultiplyByExample.java   View Source Code Vote up 5 votes
@Override
public Stream<Tuple<String>> getInput() {
    List<Tuple<String>> inputTuples = Arrays.asList(
            createMapTuple(1, 2, 3),
            createMapTuple(4, 5, 6),
            createMapTuple(7, 8, 9));
    return inputTuples.stream();
}
 
Example 15
Project: ProjectAres   File: MultiLineTextInspector.java   View Source Code Vote up 5 votes
private Stream<String> flatten(String delimiter, Stream<Stream<String>> bumpy) {
    final List<String> flat = new ArrayList<>();
    bumpy.forEachOrdered(lines -> {
        if(!flat.isEmpty()) {
            final int last = flat.size() - 1;
            flat.set(last, flat.get(last) + delimiter);
        }
        lines.forEachOrdered(flat::add);
    });
    return flat.stream();
}
 
Example 16
Project: aws-sdk-java-v2   File: ClasspathInterceptorChainFactory.java   View Source Code Vote up 5 votes
private Stream<ExecutionInterceptor> createExecutionInterceptorFromResource(URL resource) {
    try {
        if (resource == null) {
            return Stream.empty();
        }

        List<ExecutionInterceptor> interceptors = new ArrayList<>();

        try (InputStream stream = resource.openStream();
             InputStreamReader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
             BufferedReader fileReader = new BufferedReader(streamReader)) {

            String interceptorClassName = fileReader.readLine();
            while (interceptorClassName != null) {
                ExecutionInterceptor interceptor = createExecutionInterceptor(interceptorClassName);
                if (interceptor != null) {
                    interceptors.add(interceptor);
                }
                interceptorClassName = fileReader.readLine();
            }
        }

        return interceptors.stream();
    } catch (IOException e) {
        throw new SdkClientException("Unable to instantiate execution interceptor chain.", e);
    }
}
 
Example 17
Project: openjdk-jdk10   File: ModuleReferences.java   View Source Code Vote up 5 votes
@Override
Stream<String> implList() throws IOException {
    // take snapshot to avoid async close
    List<String> names = jf.stream()
            .filter(e -> e.section() == JmodFile.Section.CLASSES)
            .map(JmodFile.Entry::name)
            .collect(Collectors.toList());
    return names.stream();
}
 
Example 18
Project: koryphe   File: DivideExample.java   View Source Code Vote up 5 votes
@Override
public Stream<Tuple2<Integer, Integer>> getInput() {
    List<Tuple2<Integer, Integer>> inputTuples = Arrays.asList(
            new Tuple2<>(8, 1),
            new Tuple2<>(8, 2),
            new Tuple2<>(8, 3));
    return inputTuples.stream();
}
 
Example 19
Project: Mastering-Software-Testing-with-JUnit-5   File: CucumberTest.java   View Source Code Vote up 4 votes
@TestFactory
public Stream<DynamicTest> runTests(Stream<DynamicTest> scenarios) {
    List<DynamicTest> tests = scenarios.collect(Collectors.toList());
    return tests.stream();
}
 
Example 20
Project: tg-eventstore   File: JavaInMemoryEventStore.java   View Source Code Vote up 4 votes
@Override
public Stream<ResolvedEvent> readAllBackwards() {
    List<ResolvedEvent> reversed = new ArrayList<>(events);
    Collections.reverse(reversed);
    return reversed.stream();
}