package at.oefai.aaa.agent.jam;

import java.util.Vector;

/**
 * Represents alternative-path plan components.
 *
 * @author Marc Huber
 * @author Jaeho Lee
 */
class PlanDoAllConstruct implements PlanConstruct {

    private Vector<PlanSequenceConstruct> branches;

    /**  */
    PlanDoAllConstruct() {
        this.branches = new Vector<PlanSequenceConstruct>(1, 1);
    }

    /**  */
    PlanDoAllConstruct(PlanSequenceConstruct s) {
        this.branches = new Vector<PlanSequenceConstruct>(1, 1);
        addBranch(s);
    }

    // Member functions

    int getNumBranches() {
        return this.branches.size();
    }

    /**  */
    public PlanRuntimeState newRuntimeState() {
        return new PlanRuntimeDoAllState(this);
    }

    /**  */
    PlanSequenceConstruct getBranch(int branchnum) {
        return (branchnum >= 0 && branchnum < this.branches.size()) ? this.branches.elementAt(branchnum) : null;
    }

    /**  */
    void addBranch(PlanConstruct be) {
        if (be != null) {
            if (be instanceof PlanSequenceConstruct) {
                this.branches.addElement((PlanSequenceConstruct) be);
            } else {
                PlanSequenceConstruct ns;
                ns = new PlanSequenceConstruct(be);
                this.branches.addElement(ns);
            }
        }
    }

}
