Ejemplo n.º 1
0
  public Date getDateForEffort(double hours) {

    int week = getStartWeek();
    double defaultHoursPerWeek = getHoursPerWeek();

    while (hours > FUZZ_FACTOR) {
      if (week > maxExceptionWeek) {
        if (defaultHoursPerWeek > 0) {
          double remainingWeeks = hours / defaultHoursPerWeek;
          return weekValueToDate(week + remainingWeeks);
        } else {
          return null;
        }
      }

      double hoursThisWeek;
      WeekData exception = (WeekData) exceptions.get(week);
      if (exception != null) hoursThisWeek = exception.getHours();
      else hoursThisWeek = defaultHoursPerWeek;

      if (hours < hoursThisWeek) {
        double fractionalWeek = hours / hoursThisWeek;
        return weekValueToDate(week + fractionalWeek);
      }

      hours = hours - hoursThisWeek;
      week++;
    }

    return weekValueToDate(week);
  }
Ejemplo n.º 2
0
 private int getTypeOfWeek(Object obj) {
   if (obj instanceof WeekData) {
     WeekData wd = (WeekData) obj;
     return wd.getType();
   }
   return -1;
 }
Ejemplo n.º 3
0
  protected void getAsMap(Map<String, Object> result) {
    result.put(START_WEEK_ATTR, startWeek);
    result.put(END_WEEK_ATTR, endWeek);
    result.put(HOURS_PER_WEEK_ATTR, hoursPerWeek.getHours());

    for (Iterator i = exceptions.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry e = (Map.Entry) i.next();
      String attr = EXCEPTION_TAG + "_" + e.getKey();
      WeekData wd = (WeekData) e.getValue();
      result.put(attr, wd.getHours());
    }
  }
Ejemplo n.º 4
0
  public void writeAttributes(Writer out, boolean dumpMode) throws IOException {
    // write the start date.  This is used by the dump/sync, and also used
    // by legacy WBS Editor code (which doesn't use week numbers)
    out.write(" " + START_DATE_ATTR + "='");
    Date startDate = getStartDate();
    out.write(XMLUtils.saveDate(truncToGMT(startDate)));
    if (dumpMode) {
      // write out the calendar start date
      out.write("' " + START_CALENDAR_ATTR + "='");
      out.write(CALENDAR_DATE_FMT.format(startDate));
    } else {
      // write out the schedule start week
      out.write("' " + START_WEEK_ATTR + "='");
      out.write(Integer.toString(startWeek));
    }

    // write the end week, if applicable
    if (endWeek != NO_END) {
      int week = endWeek;
      if (dumpMode) week = week - startWeek;
      out.write("' " + END_WEEK_ATTR + "='");
      out.write(Integer.toString(week));
    }

    // write the default hours per week
    out.write("' " + HOURS_PER_WEEK_ATTR + "='");
    out.write(Double.toString(hoursPerWeek.getHours()));
    out.write("'");
  }
Ejemplo n.º 5
0
  public void writeExceptions(Writer out, boolean dumpMode) throws IOException {
    Map<Integer, WeekData> exceptions = new TreeMap(this.exceptions);
    for (Entry<Integer, WeekData> e : exceptions.entrySet()) {
      int week = e.getKey().intValue();
      if (dumpMode) {
        if (week < startWeek || week >= endWeek) continue;
        week = week - startWeek;
      }

      out.write("    <" + EXCEPTION_TAG + " " + WEEK_ATTR + "='");
      out.write(Integer.toString(week));
      out.write("' " + HOURS_ATTR + "='");
      WeekData wd = e.getValue();
      out.write(Double.toString(wd.getHours()));
      out.write("'/>\n");
    }
  }
Ejemplo n.º 6
0
  public void setWeekData(int week, Object value) {
    int type = getTypeOfWeek(value);
    if (type == WeekData.TYPE_START) {
      startWeek = week + 1;
      endWeek = Math.max(startWeek, endWeek);

    } else if (type == WeekData.TYPE_END) {
      endWeek = week;
      startWeek = Math.min(startWeek, endWeek);

    } else if (value == null || "".equals(value)) {
      if (exceptions.containsKey(week)) removeException(week);
      else addException(week, 0);

    } else if (value instanceof Number) {
      double hours = ((Number) value).doubleValue();
      if (eq(hours, hoursPerWeek.getHours())) removeException(week);
      else if (hours >= 0) addException(week, hours);
    }
  }
Ejemplo n.º 7
0
 public double getHoursPerWeek() {
   return hoursPerWeek.getHours();
 }