org.cactoos.collection.Filtered Java Examples

The following examples show how to use org.cactoos.collection.Filtered. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServletResponseFake.java    From takes with MIT License 6 votes vote down vote up
@Override
public Collection<String> getHeaders(final String header) {
    final String prefix = String.format(
        "%s",
        new Lowered(header)
    );
    try {
        return new Filtered<>(
            hdr -> new StartsWith(
                new Lowered(hdr), new TextOf(prefix)
            ).value(),
            this.response.get().head()
        );
    } catch (final IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example #2
Source File: Index.java    From jpeek with MIT License 5 votes vote down vote up
@Override
public Iterator<Directive> iterator() {
    return new Directives()
        .add("index")
        .attr("artifact", "unknown")
        .append(new Header())
        .append(
            () -> new Directives()
                .attr(
                    "xmlns:xsi",
                    "http://www.w3.org/2001/XMLSchema-instance"
                    )
                .attr(
                "xsi:noNamespaceSchemaLocation",
                "xsd/index.xsd"
                )
                .iterator()
        )
        .append(
            new Joined<>(
                new Mapped<>(
                    Index::metric,
                    new Filtered<>(
                        path -> path.getFileName().toString().matches(
                            "^[A-Z].+\\.xml$"
                        ),
                        new Directory(this.output)
                    )
                )
            )
        )
        .iterator();
}
 
Example #3
Source File: Matrix.java    From jpeek with MIT License 4 votes vote down vote up
@Override
public Iterator<Directive> iterator() {
    final SortedMap<String, Map<String, String>> matrix = new TreeMap<>();
    new Unchecked<>(
        new And(
            path -> {
                new And(
                    node -> {
                        final String name = String.format(
                            "%s.%s",
                            node.xpath("../../package/@id").get(0),
                            node.xpath("@id").get(0)
                        );
                        matrix.putIfAbsent(name, new TreeMap<>());
                        matrix.get(name).put(
                            node.xpath("/metric/title/text()").get(0),
                            node.xpath("@color").get(0)
                        );
                    },
                    new XMLDocument(path.toFile()).nodes("//class")
                ).value();
            },
            new Filtered<>(
                path -> path.getFileName().toString().matches(
                    "^[A-Z].+\\.xml$"
                ),
                new Directory(this.output)
            )
        )
    ).value();
    return new Directives()
        .add("matrix")
        .append(new Header())
        .append(
            () -> new Directives()
                .attr(
                    "xmlns:xsi",
                    "http://www.w3.org/2001/XMLSchema-instance"
                )
                .attr(
                    "xsi:noNamespaceSchemaLocation",
                    "xsd/matrix.xsd"
                )
                .iterator())
        .add("classes")
        .append(
            new Joined<Directive>(
                new Mapped<>(
                    ent -> new Directives().add("class").append(
                        new Joined<Directive>(
                            new Mapped<>(
                                mtd -> new Directives()
                                    .add("metric")
                                    .attr("name", mtd.getKey())
                                    .attr("color", mtd.getValue())
                                    .attr(
                                        "rank",
                                        Matrix.rank(mtd.getValue())
                                    )
                                    .up(),
                                ent.getValue().entrySet()
                            )
                        )
                    ).attr("id", ent.getKey()).up(),
                    matrix.entrySet()
                )
            )
        )
        .iterator();
}
 
Example #4
Source File: Classes.java    From jpeek with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings({
    "PMD.PrematureDeclaration",
    "PMD.GuardLogStatement"
})
public Iterator<CtClass> iterator() {
    final Collection<CtClass> classes;
    final long start = System.currentTimeMillis();
    try {
        classes = new Filtered<>(
            // @checkstyle BooleanExpressionComplexityCheck (10 lines)
            ctClass -> !ctClass.isInterface()
                && !ctClass.isEnum()
                && !ctClass.isAnnotation()
                && !ctClass.getName().matches("^.+\\$[0-9]+$")
                && !ctClass.getName().matches("^.+\\$AjcClosure[0-9]+$"),
            new Mapped<>(
                path -> {
                    try (InputStream stream = Files.newInputStream(path)) {
                        return this.pool.makeClassIfNew(stream);
                    }
                },
                new Filtered<>(
                    path -> Files.isRegularFile(path)
                        && path.toString().endsWith(".class"),
                    new CollectionOf<>(this.base.files())
                )
            )
        );
    } catch (final IOException ex) {
        throw new IllegalStateException(ex);
    }
    final Collection<CtClass> unique = new TreeSet<>(
        Comparator.comparing(CtClass::getName)
    );
    unique.addAll(classes);
    Logger.debug(
        this, "%d classes found and parsed via Javassist in %[ms]s",
        unique.size(), System.currentTimeMillis() - start
    );
    return unique.iterator();
}
 
Example #5
Source File: CactoosCollectionUtils.java    From tutorials with MIT License 4 votes vote down vote up
public Collection<String> getFilteredList(List<String> strings) {
	Collection<String> filteredStrings = new ListOf<>(
			new Filtered<>(string -> string.length() == 5, new IterableOf<>(strings)));
	return filteredStrings;
}