ItEr36S11CUCreacionUnidadesPlanificacionItEr35S12: Moving methods to AllocationBeingModified
This commit is contained in:
parent
ef55cc26b2
commit
3f6befa6aa
7 changed files with 69 additions and 72 deletions
|
|
@ -214,8 +214,7 @@ public class GenericResourceAllocation extends
|
|||
return GenericDayAssignment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DayAssignment> createAssignmentsAtDay(
|
||||
public List<DayAssignment> createAssignmentsAtDay(
|
||||
List<Resource> resources, LocalDate day,
|
||||
ResourcesPerDay resourcesPerDay, final int maxLimit) {
|
||||
final int hours = Math.min(calculateTotalToDistribute(day,
|
||||
|
|
|
|||
|
|
@ -169,11 +169,9 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
|
||||
@Override
|
||||
protected List<DayAssignment> createAssignmentsAtDay(
|
||||
ResourceAllocation<?> resourceAllocation,
|
||||
List<Resource> resources, LocalDate day,
|
||||
ResourcesPerDay resourcesPerDay, Integer limit) {
|
||||
return resourceAllocation.createAssignmentsAtDay(resources,
|
||||
day, resourcesPerDay, limit);
|
||||
AllocationBeingModified allocation, LocalDate day,
|
||||
Integer limit) {
|
||||
return allocation.createAssignmentsAtDay(day, limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -212,10 +210,6 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
|
||||
public abstract List<Resource> getAssociatedResources();
|
||||
|
||||
protected abstract List<DayAssignment> createAssignmentsAtDay(
|
||||
List<Resource> resources, LocalDate day,
|
||||
ResourcesPerDay resourcesPerDay, int limit);
|
||||
|
||||
protected void setResourcesPerDay(ResourcesPerDay resourcesPerDay) {
|
||||
Validate.notNull(resourcesPerDay);
|
||||
this.resourcesPerDay = resourcesPerDay;
|
||||
|
|
|
|||
|
|
@ -149,9 +149,7 @@ public class SpecificResourceAllocation extends
|
|||
return SpecificDayAssignment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DayAssignment> createAssignmentsAtDay(
|
||||
List<Resource> resources, LocalDate day,
|
||||
public List<DayAssignment> createAssignmentsAtDay(LocalDate day,
|
||||
ResourcesPerDay resourcesPerDay, int limit) {
|
||||
int hours = calculateTotalToDistribute(day, resourcesPerDay);
|
||||
SpecificDayAssignment specific = SpecificDayAssignment.create(day, Math
|
||||
|
|
|
|||
|
|
@ -26,33 +26,65 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.planner.entities.DayAssignment;
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
public class AllocationBeingModified {
|
||||
public abstract class AllocationBeingModified {
|
||||
|
||||
private static class GenericAllocationBeingModified extends
|
||||
AllocationBeingModified {
|
||||
private final GenericResourceAllocation genericAllocation;
|
||||
|
||||
GenericAllocationBeingModified(
|
||||
ResourceAllocation<?> resourceAllocation,
|
||||
GenericResourceAllocation resourceAllocation,
|
||||
ResourcesPerDay resourcesPerDay,
|
||||
Collection<? extends Resource> resources) {
|
||||
super(resourceAllocation, resourcesPerDay, resources);
|
||||
Validate.isTrue(!resources.isEmpty());
|
||||
this.genericAllocation = resourceAllocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyOnTaskDuration() {
|
||||
genericAllocation.forResources(getResources()).allocate(getGoal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DayAssignment> createAssignmentsAtDay(LocalDate day,
|
||||
int limit) {
|
||||
return genericAllocation.createAssignmentsAtDay(getResources(),
|
||||
day, getGoal(), limit);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SpecificAllocationBeingModified extends
|
||||
AllocationBeingModified {
|
||||
|
||||
private final SpecificResourceAllocation resourceAllocation;
|
||||
|
||||
SpecificAllocationBeingModified(
|
||||
ResourceAllocation<?> resourceAllocation,
|
||||
SpecificResourceAllocation resourceAllocation,
|
||||
ResourcesPerDay resourcesPerDay,
|
||||
Collection<? extends Resource> resources) {
|
||||
super(resourceAllocation, resourcesPerDay, resources);
|
||||
this.resourceAllocation = resourceAllocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyOnTaskDuration() {
|
||||
resourceAllocation.allocate(getGoal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DayAssignment> createAssignmentsAtDay(LocalDate day,
|
||||
int limit) {
|
||||
return resourceAllocation.createAssignmentsAtDay(day, getGoal(),
|
||||
limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,4 +166,9 @@ public class AllocationBeingModified {
|
|||
public List<Resource> getResources() {
|
||||
return resourcesOnWhichApplyAllocation;
|
||||
}
|
||||
|
||||
public abstract void applyOnTaskDuration();
|
||||
|
||||
public abstract List<DayAssignment> createAssignmentsAtDay(LocalDate day,
|
||||
int limit);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import org.navalplanner.business.planner.entities.DayAssignment;
|
|||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
public abstract class AllocatorForSpecifiedResourcesPerDayAndHours {
|
||||
|
||||
|
|
@ -88,23 +87,16 @@ public abstract class AllocatorForSpecifiedResourcesPerDayAndHours {
|
|||
List<DayAssignment> dayAssignments);
|
||||
|
||||
protected abstract List<DayAssignment> createAssignmentsAtDay(
|
||||
ResourceAllocation<?> resourceAllocation, List<Resource> resources,
|
||||
LocalDate day, ResourcesPerDay resourcesPerDay, Integer limit);
|
||||
AllocationBeingModified allocation, LocalDate day, Integer limit);
|
||||
|
||||
private int assignForDay(LocalDate day, int toBeAssigned) {
|
||||
int i = 0;
|
||||
int total = 0;
|
||||
List<Integer> maxPerAllocations = calculateLimits(toBeAssigned);
|
||||
for (AllocationBeingModified withResourcesPerDay : allocations) {
|
||||
ResourceAllocation<?> resourceAllocation = withResourcesPerDay
|
||||
.getBeingModified();
|
||||
ResourcesPerDay resourcesPerDay = withResourcesPerDay
|
||||
.getGoal();
|
||||
List<DayAssignment> assignments = createAssignmentsAtDay(
|
||||
resourceAllocation, withResourcesPerDay.getResources(),
|
||||
day,
|
||||
resourcesPerDay, maxPerAllocations.get(i));
|
||||
resultAssignments.get(withResourcesPerDay).addAll(assignments);
|
||||
for (AllocationBeingModified each : allocations) {
|
||||
List<DayAssignment> assignments = createAssignmentsAtDay(each, day,
|
||||
maxPerAllocations.get(i));
|
||||
resultAssignments.get(each).addAll(assignments);
|
||||
total += DayAssignment.sum(assignments);
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,6 @@ package org.navalplanner.business.planner.entities.allocationalgorithms;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
public class AllocatorForTaskDurationAndSpecifiedResourcesPerDay {
|
||||
|
||||
private List<AllocationBeingModified> allocations;
|
||||
|
|
@ -39,32 +33,7 @@ public class AllocatorForTaskDurationAndSpecifiedResourcesPerDay {
|
|||
|
||||
public void allocateOnTaskLength() {
|
||||
for (AllocationBeingModified allocation : allocations) {
|
||||
doAllocationForFixedTask(allocation);
|
||||
allocation.applyOnTaskDuration();
|
||||
}
|
||||
}
|
||||
|
||||
private void doAllocationForFixedTask(
|
||||
AllocationBeingModified allocationBeingModified) {
|
||||
ResourceAllocation<?> allocation = allocationBeingModified
|
||||
.getBeingModified();
|
||||
ResourcesPerDay resourcesPerDay = allocationBeingModified.getGoal();
|
||||
if (allocation instanceof GenericResourceAllocation) {
|
||||
doAllocation((GenericResourceAllocation) allocation,
|
||||
resourcesPerDay, allocationBeingModified.getResources());
|
||||
} else {
|
||||
SpecificResourceAllocation specific = (SpecificResourceAllocation) allocation;
|
||||
doAllocation(specific, resourcesPerDay);
|
||||
}
|
||||
}
|
||||
|
||||
private void doAllocation(SpecificResourceAllocation specific,
|
||||
ResourcesPerDay resourcesPerDay) {
|
||||
specific.allocate(resourcesPerDay);
|
||||
}
|
||||
|
||||
private void doAllocation(GenericResourceAllocation generic,
|
||||
ResourcesPerDay resourcesPerDay, List<Resource> resources) {
|
||||
generic.forResources(resources).allocate(resourcesPerDay);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,19 +203,26 @@ public class AllocationUntilFillingHoursTest {
|
|||
}
|
||||
|
||||
private void givenAllocationsWithoutTask() {
|
||||
allocations.add(AllocationBeingModified.create(createStubAllocationReturning(null), ResourcesPerDay.amount(2), resources));
|
||||
allocations.add(AllocationBeingModified.create(createStubAllocationReturning(null), ResourcesPerDay.amount(2), resources));
|
||||
allocations.add(AllocationBeingModified.create(
|
||||
createStubAllocationReturning(SpecificResourceAllocation.class,
|
||||
null), ResourcesPerDay.amount(2), resources));
|
||||
allocations.add(AllocationBeingModified.create(
|
||||
createStubAllocationReturning(SpecificResourceAllocation.class,
|
||||
null), ResourcesPerDay.amount(2), resources));
|
||||
}
|
||||
|
||||
private void givenAllocationsBelongingToDifferentTasks() {
|
||||
Task task = createStubTask();
|
||||
allocations
|
||||
.add(AllocationBeingModified.create(createStubAllocationReturning(task), ResourcesPerDay.amount(2), resources));
|
||||
allocations
|
||||
.add(AllocationBeingModified.create(createStubAllocationReturning(task), ResourcesPerDay.amount(2), resources));
|
||||
allocations.add(AllocationBeingModified.create(
|
||||
createStubAllocationReturning(SpecificResourceAllocation.class,
|
||||
task), ResourcesPerDay.amount(2), resources));
|
||||
allocations.add(AllocationBeingModified.create(
|
||||
createStubAllocationReturning(SpecificResourceAllocation.class,
|
||||
task), ResourcesPerDay.amount(2), resources));
|
||||
Task other = createStubTask();
|
||||
allocations
|
||||
.add(AllocationBeingModified.create(createStubAllocationReturning(other), ResourcesPerDay.amount(2), resources));
|
||||
allocations.add(AllocationBeingModified.create(
|
||||
createStubAllocationReturning(SpecificResourceAllocation.class,
|
||||
other), ResourcesPerDay.amount(2), resources));
|
||||
}
|
||||
|
||||
private Task createStubTask() {
|
||||
|
|
@ -238,8 +245,9 @@ public class AllocationUntilFillingHoursTest {
|
|||
return result;
|
||||
}
|
||||
|
||||
private ResourceAllocation<?> createStubAllocationReturning(Task task) {
|
||||
ResourceAllocation<?> resourceAllocation = createNiceMock(ResourceAllocation.class);
|
||||
private ResourceAllocation<?> createStubAllocationReturning(
|
||||
Class<? extends ResourceAllocation<?>> allocationClass, Task task) {
|
||||
ResourceAllocation<?> resourceAllocation = createNiceMock(allocationClass);
|
||||
expect(resourceAllocation.getTask()).andReturn(task).anyTimes();
|
||||
replay(resourceAllocation);
|
||||
return resourceAllocation;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue