protected Schedule getWaterPolicySchedule(FeedingPolicy fp) {
   Vector sched_els = new Vector(0);
   if (fp != null) {
     RangeRuleParameterEntry[] waterRanges = fp.getWaterPolicyRanges();
     ObjectScheduleElement element;
     long start, end;
     // e.g., min = 0 then start is C + 0 or C - Day of the operation
     // e.g., min = 1 then start is C + 1 or 2nd day of the operation
     if (waterRanges.length > 0) {
       start =
           parentPlugin
               .getTimeUtils()
               .addNDays(logOPlan.getStartTime(), waterRanges[0].getRangeMin());
       for (int i = 0; i < waterRanges.length; i++) {
         end =
             parentPlugin
                 .getTimeUtils()
                 .addNDays(
                     start, (waterRanges[i].getRangeMax() - waterRanges[i].getRangeMin() + 1));
         KeyRuleParameterEntry[] keys = fp.getRangeKeys(waterRanges[i]);
         element =
             new ObjectScheduleElement(
                 start,
                 end,
                 addWater(new HashMap(), BOTTLED_WATER, new Double(keys[0].getValue())));
         sched_els.addElement(element);
         start = end;
       }
     }
   } // else feeding policy is null return empty schedule
   return parentPlugin.getScheduleUtils().newObjectSchedule(sched_els.elements());
 }
  private KeyRuleParameterEntry[] getActionPolicy(String activity, String optempo) {
    // This appears to happen sporadically.
    if (feedingPolicy == null) {
      if (logger.isErrorEnabled()) {
        String myOrgName = null;
        if (parentPlugin != null
            && parentPlugin.getMyOrg() != null
            && parentPlugin.getMyOrg().getItemIdentificationPG() != null)
          myOrgName = parentPlugin.getMyOrg().getItemIdentificationPG().getItemIdentification();

        logger.error(
            "Bug 2982: SubsistenceConsumerBG at Org " + myOrgName + " got null feedingPolicy!",
            new Throwable());
      }
      return null;
    }

    RangeRuleParameterEntry[] rules = feedingPolicy.getRules();
    RangeRuleParameter theRule = new RangeRuleParameter();
    KeyRuleParameterEntry[] keys;
    boolean found = false;
    boolean flag = true;
    int j = 0;
    int i = 0;
    while ((!found) && (i < rules.length)) {
      theRule = (RangeRuleParameter) rules[i].getValue();
      keys = feedingPolicy.getConditionKeys(theRule);
      j = 0;
      flag = true;
      while (flag && (j < keys.length)) {
        if ((!keys[j].getKey().equalsIgnoreCase("OrgActivity"))
            && (!keys[j].getKey().equalsIgnoreCase("Optempo"))) {
          flag = false;
        } else {
          if ((!keys[j].getValue().equalsIgnoreCase(activity))
              && (!keys[j].getValue().equalsIgnoreCase(optempo))) {
            flag = false;
          }
        }
        j++;
      }
      if (flag) {
        found = true;
      } else {
        i++;
      }
    }
    if (found) {
      return feedingPolicy.getActionKeys(theRule);
    }
    return null;
  }
 protected Schedule getEnhancementPolicySchedule(FeedingPolicy fp) {
   Vector sched_els = new Vector(0);
   String[] nsns = {FRESH_FRUITS, FRESH_VEGETABLES};
   if (fp != null) {
     RangeRuleParameterEntry[] eRanges = fp.getEnhancementsPolicyRanges();
     ObjectScheduleElement element;
     long start, end;
     // e.g., min = 0 then start is C + 0 or C - Day of the operation
     // e.g., min = 1 then start is C + 1 or 2nd day of the operation
     if (eRanges.length > 0) {
       start =
           parentPlugin.getTimeUtils().addNDays(logOPlan.getStartTime(), eRanges[0].getRangeMin());
       for (int i = 0; i < eRanges.length; i++) {
         end =
             parentPlugin
                 .getTimeUtils()
                 .addNDays(start, (eRanges[i].getRangeMax() - eRanges[i].getRangeMin() + 1));
         element =
             new ObjectScheduleElement(start, end, addEnhancements(new HashMap(), nsns, i, fp));
         sched_els.addElement(element);
         start = end;
       }
     }
   } // else feeding policy is null return empty schedule
   return parentPlugin.getScheduleUtils().newObjectSchedule(sched_els.elements());
 }
 private HashMap addEnhancements(HashMap enhance, String[] nsn_keys, int j, FeedingPolicy fp) {
   KeyRuleParameterEntry[] keys = fp.getEnhancementsKeys(j);
   for (int i = 0; i < keys.length; i++) {
     enhance.put(nsn_keys[i], new Double(keys[i].getValue()));
   }
   return enhance;
 }
 private HashMap addMeals(HashMap map, int j, FeedingPolicy p) {
   RangeRuleParameterEntry[] meals; // bRanges, lRanges, dRanges;
   meals = p.getMealPolicyRanges();
   if (meals == null) {
     return map;
   } // if
   KeyRuleParameterEntry[] keys = p.getRangeKeys(meals[j]);
   String nsn;
   for (int i = 0; i < keys.length; i++) {
     nsn = keys[i].getValue().toString();
     if (nsn != null && nsn.length() > 0) {
       calculateConsumptionRate(map, nsn);
       map = addSupplementRate(map, nsn);
     } // if
   } // for
   return map;
 } // addMeals
 /**
  * Get the mandatory supplements from the property group and create a map that contains the daily
  * consumption rate for both the supplements and the meals for a given range.
  *
  * @param policy the feeding policy
  * @return Vector of ObjectScheduleElements
  */
 private Vector createMealAndSupplementSchedule(FeedingPolicy policy) {
   Vector sched_els = new Vector();
   if (policy != null) {
     RangeRuleParameterEntry[] mealRanges = policy.getMealPolicyRanges();
     ObjectScheduleElement element;
     for (int i = 0; i < mealRanges.length; i++) {
       element =
           new ObjectScheduleElement(
               mealRanges[i].getRangeMin(),
               mealRanges[i].getRangeMax(),
               addMeals(new HashMap(), i, policy));
       sched_els.addElement(element);
     } // for
   } // if
   return sched_els;
 } // createMealAndSupplementSchedule