package org.studiorailgun.knowledge.query.filter;

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

import org.studiorailgun.knowledge.Node;
import org.studiorailgun.knowledge.query.InstanceQuery;

/**
 * Filter nodes to just instances of a specific node
 */
public class InstanceQueryFilter {
    
    /**
     * Filters nodes to just those that are instanced of the category
     * @param collection The collection of nodes
     * @param category The category to filter to
     * @return The list of ndoes within that category
     */
    public static List<Node> filter(List<Node> collection, Node category){
        List<Node> categoryInstances = InstanceQuery.getInstances(category);
        return collection.stream().filter(node -> categoryInstances.contains(node)).collect(Collectors.toList());
    }

}
