private void apply(ResourceAllocation<?> resourceAllocation,
LocalDate start, LocalDate end, int totalHours) {
final LocalDate previousEndDate = resourceAllocation.getEndDate();
EffortDuration capacity;
BaseCalendar calendar = resourceAllocation.getTask().getCalendar();
int daysDuration = daysWithAllocatedHours(resourceAllocation).size();
// Calculate hours per day and round values
BigDecimal[] hoursToAllocatePerDay = generateHoursToAllocateFor(daysDuration, totalHours);
hoursToAllocatePerDay = roundValues(hoursToAllocatePerDay, HOUR_FRAGMENTATION);
// Calculate reminder (difference between totalHours and sum of hours calculated)
BigDecimal totalHoursToAllocate = sumHoursPerDay(hoursToAllocatePerDay);
assert(totalHoursToAllocate.compareTo(BigDecimal.valueOf(totalHours)) <= 0);
BigDecimal remindingHours = BigDecimal.valueOf(totalHours).subtract(totalHoursToAllocate);
allocateRemindingHours(hoursToAllocatePerDay, remindingHours);
avoidZeroHoursInDays(hoursToAllocatePerDay);
assert(hoursToAllocatePerDay.length == daysDuration);
// Starting from startDate do allocation, one slot of hours per day in resource
LocalDate day = new LocalDate(start);
EffortDuration hours = EffortDuration.zero();
int i = 0;
while (i < hoursToAllocatePerDay.length) {
hours = EffortDuration
.fromHoursAsBigDecimal(hoursToAllocatePerDay[i]);
capacity = calendar.getCapacityOn(PartialDay.wholeDay(day));