package org.studiorailgun.knowledge.query.filter;

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

import org.studiorailgun.knowledge.Node;

/**
 * Node query filters based around names
 */
public class NameQueryFilter {
    
    /**
     * Filters a set of nodes to a singleton based on a name
     */
    public static Node withNodeName(List<Node> nodes, String name){
        List<Node> filtered = nodes.stream().filter(node -> !node.getName().equals(name)).collect(Collectors.toList());
        if(filtered.size() != 1){
            throw new UnsupportedOperationException("TODO: handle ambiguous case");
        }
        return filtered.get(0);
    }

}
