Bug #1428: Bring all files related to IAssignedEffortForResource to one unique file
This commit is contained in:
parent
6a8b0ba9c8
commit
628f192be4
5 changed files with 33 additions and 55 deletions
|
|
@ -1,9 +1,7 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
* Copyright (C) 2010-2011 Igalia, S.L.
|
||||
* Copyright (C) 2012 Óscar González Fernández
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
@ -21,7 +19,6 @@
|
|||
package org.libreplan.business.planner.entities;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -30,21 +27,35 @@ import org.libreplan.business.common.BaseEntity;
|
|||
import org.libreplan.business.resources.entities.Resource;
|
||||
import org.libreplan.business.workingday.EffortDuration;
|
||||
|
||||
public class AssignedEffortDiscounting implements
|
||||
IAssignedEffortForResource {
|
||||
/**
|
||||
* @author Oscar Gonzalez Fernandez <ogfernandez@gmail.com>
|
||||
*/
|
||||
public class AssignedEffortForResource {
|
||||
|
||||
private final Map<Long, Set<BaseEntity>> allocations;
|
||||
public interface IAssignedEffortForResource {
|
||||
|
||||
public AssignedEffortDiscounting(BaseEntity allocationToDiscountFrom) {
|
||||
this(Collections.singleton(allocationToDiscountFrom));
|
||||
public EffortDuration getAssignedDurationAt(Resource resource,
|
||||
LocalDate day);
|
||||
}
|
||||
|
||||
AssignedEffortDiscounting(Collection<? extends BaseEntity> discountFrom) {
|
||||
this.allocations = BaseEntity.byId(discountFrom);
|
||||
public static IAssignedEffortForResource discount(
|
||||
Collection<? extends BaseEntity> allocations) {
|
||||
return new AssignedEffortDiscounting(allocations);
|
||||
}
|
||||
|
||||
public EffortDuration getAssignedDurationAt(Resource resource, LocalDate day) {
|
||||
return resource.getAssignedDurationDiscounting(allocations, day);
|
||||
private static class AssignedEffortDiscounting implements
|
||||
IAssignedEffortForResource {
|
||||
|
||||
private final Map<Long, Set<BaseEntity>> allocations;
|
||||
|
||||
AssignedEffortDiscounting(Collection<? extends BaseEntity> discountFrom) {
|
||||
this.allocations = BaseEntity.byId(discountFrom);
|
||||
}
|
||||
|
||||
public EffortDuration getAssignedDurationAt(Resource resource,
|
||||
LocalDate day) {
|
||||
return resource.getAssignedDurationDiscounting(allocations, day);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import static org.libreplan.business.workingday.EffortDuration.zero;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -104,7 +105,7 @@ public class DerivedAllocationGenerator {
|
|||
List<? extends DayAssignment> dayAssignments) {
|
||||
List<DerivedDayAssignment> result = new ArrayList<DerivedDayAssignment>();
|
||||
EffortDistributor distributor = new EffortDistributor(resourcesFound,
|
||||
new AssignedEffortDiscounting(parent));
|
||||
AssignedEffortForResource.discount(Collections.singletonList(parent)));
|
||||
for (DayAssignment each : dayAssignments) {
|
||||
int durationInSeconds = alpha.multiply(
|
||||
new BigDecimal(each.getDuration().getSeconds())).intValue();
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import org.libreplan.business.calendars.entities.Capacity;
|
|||
import org.libreplan.business.calendars.entities.ICalendar;
|
||||
import org.libreplan.business.calendars.entities.ResourceCalendar;
|
||||
import org.libreplan.business.calendars.entities.SameWorkHoursEveryDay;
|
||||
import org.libreplan.business.planner.entities.AssignedEffortForResource.IAssignedEffortForResource;
|
||||
import org.libreplan.business.resources.entities.Resource;
|
||||
import org.libreplan.business.workingday.EffortDuration;
|
||||
import org.libreplan.business.workingday.IntraDayDate.PartialDay;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import org.joda.time.LocalDate;
|
|||
import org.libreplan.business.calendars.entities.AvailabilityTimeLine;
|
||||
import org.libreplan.business.calendars.entities.Capacity;
|
||||
import org.libreplan.business.calendars.entities.ICalendar;
|
||||
import org.libreplan.business.planner.entities.AssignedEffortForResource.IAssignedEffortForResource;
|
||||
import org.libreplan.business.planner.entities.EffortDistributor.IResourceSelector;
|
||||
import org.libreplan.business.planner.entities.EffortDistributor.ResourceWithAssignedDuration;
|
||||
import org.libreplan.business.planner.entities.allocationalgorithms.ResourcesPerDayModification;
|
||||
|
|
@ -241,15 +242,16 @@ public class GenericResourceAllocation extends
|
|||
|
||||
public void discountAssignedHoursForResourceFrom(
|
||||
Collection<? extends ResourceAllocation<?>> allocations) {
|
||||
assignedEffortCalculatorOverriden = new AssignedEffortDiscounting(
|
||||
allocations);
|
||||
assignedEffortCalculatorOverriden = AssignedEffortForResource
|
||||
.discount(allocations);
|
||||
}
|
||||
|
||||
private IAssignedEffortForResource getAssignedEffortForResource() {
|
||||
if (assignedEffortCalculatorOverriden != null) {
|
||||
return assignedEffortCalculatorOverriden;
|
||||
}
|
||||
return new AssignedEffortDiscounting(this);
|
||||
return AssignedEffortForResource.discount(Collections
|
||||
.singletonList(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -286,8 +288,6 @@ public class GenericResourceAllocation extends
|
|||
ResourceAllocation<GenericDayAssignment> createCopy(Scenario scenario) {
|
||||
GenericResourceAllocation allocation = create();
|
||||
allocation.criterions = new HashSet<Criterion>(criterions);
|
||||
allocation.assignedEffortCalculatorOverriden = new AssignedEffortDiscounting(
|
||||
this);
|
||||
return allocation;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
* Copyright (C) 2010-2011 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.libreplan.business.planner.entities;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.resources.entities.Resource;
|
||||
import org.libreplan.business.workingday.EffortDuration;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*
|
||||
*/
|
||||
public interface IAssignedEffortForResource {
|
||||
|
||||
public EffortDuration getAssignedDurationAt(Resource resource, LocalDate day);
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue