/**
 * PDDL Graph Planner
 * Zeyn Saigol <zeyn@zeyn.net>
 * School of Computer Science
 * University of Birmingham
 *
 * $Id: PredicateHeader.java 32 2007-02-21 16:29:39Z zas $
 */
package uk.ac.bham.cs.zas.pddl.domain;

import java.util.*;

/**
 * Placeholder for a predicate used in an {@link ActionDef} before actual objects
 * have been matched to the action arguments. Replaced by an {@link PredicateInstance}
 * when objects are instantiated.
 */
public class PredicateHeader implements GoalDesc
{
    private final PredicateDef definition;
    private final List<FormalArgument> arguments;
    
    public PredicateHeader(final PredicateDef definition, final List<FormalArgument> arguments) {
        this.definition = definition;
        this.arguments = arguments;
    }

    public boolean evaluate(ConsistentLiteralSet literals) {
        throw new UnsupportedOperationException("Predicate headers are not evaluable (predicate " 
                                                + definition.getName() + ")");
    }
    
    public void getLiteralsUsed(Set<LiteralInstance> resultSet)
    {
        throw new UnsupportedOperationException("Predicate headers are not evaluable (predicate " 
                                                + definition.getName() + ")");
    }
    
    public boolean isEvaluable() {
        return false;
    }
    
    public GoalDesc instantiate(Map<FormalArgument, PDDLObject> parameters, Set<PDDLObject> objects) {
        List<PDDLObject> actualArgs = new ArrayList<PDDLObject>(arguments.size());
        for (FormalArgument a : arguments) {
            PDDLObject obj = parameters.get(a);
            if (obj == null) {
                throw new IllegalStateException("No argument suppled for " + a.getName());
            }
            actualArgs.add(obj);
        }
        return new PredicateInstance(definition, actualArgs);
    }
    
    public String toString()
    {
        return definition.getName() + arguments;
    }
}
