jill/src/main/java/io/github/agentsoz/jill/lang/PlanBindings.java
public Plan selectPlan(PlanSelectionPolicy policy) {
    Plan plan = null;
    int index = 0;
    switch (policy) {
      case FIRST:
      case LAST:
        Plan[] plans = bindings.keySet().toArray(new Plan[0]);
        plan = (policy == PlanSelectionPolicy.FIRST) ? plans[0] : plans[plans.length - 1];
        index = (policy == PlanSelectionPolicy.FIRST) ? 0 : plans.length - 1;
        setPlanVariables(plan.getAgent(), plan, bindings.get(plan), index);
        break;
      case RANDOM:
        plan = selectPlanAtRandom();
        break;
      default:
        // TODO: ignore remaining polic
        break;
    }
    return plan;
  }
public Plan selectPlan(PlanSelectionPolicy policy) {
    Plan plan = null;
    int index = 0;
    switch (policy) {
      case FIRST:
      case LAST:
        Plan[] plans = bindings.keySet().toArray(new Plan[0]);
        plan = (policy == PlanSelectionPolicy.FIRST) ? plans[0] : plans[plans.length - 1];
        index = (policy == PlanSelectionPolicy.FIRST) ? 0 : plans.length - 1;
        setPlanVariables(plan.getAgent(), plan, bindings.get(plan), index);
        break;
      case RANDOM:
        plan = selectPlanAtRandom();
        break;
      default:
        // TODO: ignore remaining polic
        break;
    }
    return plan;
  }
Selects a plan instance from the set of plan bindings, using the given policy.

@param policy the policy to use for plan selection
@return the selected plan, or {@code null} if something went wrong