ItEr26S07CUAsignacionGrupoRecursosAPlanificacionItEr25S07: A ResourceAllocation can calculate the assigned hours

This commit is contained in:
Óscar González Fernández 2009-09-15 10:17:19 +02:00
parent 3b839d900a
commit 988e1ae666
4 changed files with 29 additions and 0 deletions

View file

@ -97,4 +97,11 @@ public abstract class DayAssigment extends BaseEntity {
};
}
public static <T extends DayAssigment> List<T> orderedByDay(
Collection<T> dayAssignments) {
List<T> result = new ArrayList<T>(dayAssignments);
Collections.sort(result, byDayComparator());
return result;
}
}

View file

@ -193,4 +193,9 @@ public class GenericResourceAllocation extends ResourceAllocation {
clearFieldsCalculatedFromAssignments();
}
@Override
protected List<? extends DayAssigment> getAssignments() {
return DayAssigment.orderedByDay(genericDayAssigments);
}
}

View file

@ -4,6 +4,7 @@
package org.navalplanner.business.planner.entities;
import java.math.BigDecimal;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.NotNull;
@ -65,4 +66,14 @@ public abstract class ResourceAllocation extends BaseEntity {
return assigmentFunction;
}
public int getAssignedHours() {
int total = 0;
for (DayAssigment dayAssigment : getAssignments()) {
total += dayAssigment.getHours();
}
return total;
}
protected abstract List<? extends DayAssigment> getAssignments();
}

View file

@ -2,6 +2,7 @@ package org.navalplanner.business.planner.entities;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.validator.NotNull;
@ -46,4 +47,9 @@ public class SpecificResourceAllocation extends ResourceAllocation {
public Set<SpecificDayAssigment> getSpecificDaysAssigment() {
return Collections.unmodifiableSet(specificDaysAssigment);
}
@Override
protected List<? extends DayAssigment> getAssignments() {
return DayAssigment.orderedByDay(specificDaysAssigment);
}
}