All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.gofabian.jfixture.FixtureDefinitionQueries Maven / Gradle / Ivy

The newest version!
package de.gofabian.jfixture;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class FixtureDefinitionQueries {

    private final List definitions;

    public FixtureDefinitionQueries(List definitions) {
        this.definitions = definitions;
    }

    public List filterBy(Predicate predicate) {
        return definitions.stream().filter(predicate).collect(Collectors.toList());
    }

    public FixtureDefinition findByType(Class type) {
        var it = definitions.listIterator(definitions.size());
        while (it.hasPrevious()) {
            var definition = it.previous();
            if (supportsType(definition, type)) {
                return definition;
            }
        }
        return null;
    }

    private static boolean supportsType(FixtureDefinition definition, Class type) {
        return type.isAssignableFrom(definition.getType());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy