package ac.essex.gp.ooechs.novelty1.nodes.functions;

import ac.essex.gp.tree.Node;
import ac.essex.gp.params.NodeConstraints;
import ac.essex.gp.problems.DataStack;

import java.util.Vector;

/**
 * Gets the range in height between a series of features contained
 * within a vector.
 *
 * @author Olly Oechsle, University of Essex, Date: 16-Apr-2008
 * @version 1.0
 */
public class Count extends Node {

    public Count()  {
        super(1);
    }

    public int getReturnType() {
        return NodeConstraints.NUMBER;
    }

    public double execute(DataStack data) {
        child[0].execute(data);
        Vector features = (Vector) data.getData();
        data.value = features.size();
        return debugger.record(data.value);
    }

    public String toJava() {
        return "count(" + child[0].getName() + ")";
    }

    public int getChildType(int i) {
        return NodeConstraints.VECTOR;
    }

}
