ItEr41S09RFSoporteRecursosVirtuaisItEr40S12: Adding toHours method

This commit is contained in:
Óscar González Fernández 2009-12-28 17:08:52 +01:00
parent 639b62485a
commit 600c87936a
5 changed files with 63 additions and 0 deletions

View file

@ -32,6 +32,7 @@ import org.joda.time.DateTimeConstants;
import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.entities.CalendarData.Days;
import org.navalplanner.business.common.BaseEntity;
import org.navalplanner.business.planner.entities.ResourcesPerDay;
/**
* Represents a calendar with some exception days. A calendar is valid till the
@ -258,6 +259,10 @@ public class BaseCalendar extends BaseEntity implements IWorkHours {
* calendar restrictions.
*/
public Integer getCapacityAt(LocalDate date) {
return getWorkableHours(date);
}
private Integer getWorkableHours(LocalDate date) {
CalendarException exceptionDay = getExceptionDay(date);
if (exceptionDay != null) {
return exceptionDay.getHours();
@ -774,4 +779,10 @@ public class BaseCalendar extends BaseEntity implements IWorkHours {
calendarAvailability.setEndDate(endDate);
}
@Override
public Integer toHours(LocalDate day, ResourcesPerDay resourcesPerDay) {
final Integer workableHours = getWorkableHours(day);
return resourcesPerDay.asHoursGivenResourceWorkingDayOf(workableHours);
}
}

View file

@ -25,6 +25,7 @@ import java.util.List;
import org.apache.commons.lang.Validate;
import org.joda.time.LocalDate;
import org.navalplanner.business.planner.entities.ResourcesPerDay;
public abstract class CombinedWorkHours implements IWorkHours {
@ -52,6 +53,22 @@ public abstract class CombinedWorkHours implements IWorkHours {
return current;
}
@Override
public Integer toHours(LocalDate day, ResourcesPerDay amount) {
Integer current = null;
for (IWorkHours each : workHours) {
current = current == null ? initialHours(each, day, amount)
: updateHours(current, each, day, amount);
}
return current;
}
protected abstract Integer updateHours(Integer current,
IWorkHours workHours, LocalDate day, ResourcesPerDay amount);
protected abstract Integer initialHours(IWorkHours workHours,
LocalDate day, ResourcesPerDay amount);
protected abstract Integer capacity(IWorkHours workHour, LocalDate date);
protected abstract Integer updateCapacity(Integer current,
@ -75,4 +92,17 @@ class Min extends CombinedWorkHours {
protected Integer capacity(IWorkHours workHour, LocalDate date) {
return workHour.getCapacityAt(date);
}
@Override
protected Integer initialHours(IWorkHours workHours, LocalDate day,
ResourcesPerDay amount) {
return workHours.toHours(day, amount);
}
@Override
protected Integer updateHours(Integer current, IWorkHours workHours,
LocalDate day, ResourcesPerDay amount) {
return Math.min(workHours.toHours(day, amount), current);
}
}

View file

@ -21,9 +21,19 @@
package org.navalplanner.business.calendars.entities;
import org.joda.time.LocalDate;
import org.navalplanner.business.planner.entities.ResourcesPerDay;
public interface IWorkHours {
/**
* Translates the received amount into the corresponding hours at the given
* date
* @param day
* @param amount
* @return
*/
public Integer toHours(LocalDate day, ResourcesPerDay amount);
/**
* Calculates the capacity at a given date. It means all the hours that
* could be worked without having overtime

View file

@ -22,6 +22,7 @@ package org.navalplanner.business.calendars.entities;
import org.apache.commons.lang.Validate;
import org.joda.time.LocalDate;
import org.navalplanner.business.planner.entities.ResourcesPerDay;
public class SameWorkHoursEveryDay implements IWorkHours {
@ -44,4 +45,9 @@ public class SameWorkHoursEveryDay implements IWorkHours {
return hours;
}
@Override
public Integer toHours(LocalDate day, ResourcesPerDay amount) {
return amount.asHoursGivenResourceWorkingDayOf(getCapacityAt(day));
}
}

View file

@ -486,6 +486,12 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
return getTaskCalendar().getCapacityAt(day);
}
}
@Override
public Integer toHours(LocalDate day, ResourcesPerDay amount) {
final Integer capacity = getCapacityAt(day);
return amount.asHoursGivenResourceWorkingDayOf(capacity);
}
};
}