ItEr36S11CUCreacionUnidadesPlanificacionItEr35S12: Adding properties to AggregatedHours needed by resource task allocation form
This commit is contained in:
parent
d8ac1f018a
commit
fc3d58f168
2 changed files with 52 additions and 2 deletions
|
|
@ -29,6 +29,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
|
||||
/**
|
||||
|
|
@ -52,6 +53,14 @@ public class AggregatedHoursGroup {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static int sum(Collection<? extends AggregatedHoursGroup> aggregated) {
|
||||
int result = 0;
|
||||
for (AggregatedHoursGroup each : aggregated) {
|
||||
result += each.getHours();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Map<Set<Criterion>, List<HoursGroup>> byCriterions(
|
||||
Collection<? extends HoursGroup> hours) {
|
||||
Map<Set<Criterion>, List<HoursGroup>> result = new HashMap<Set<Criterion>, List<HoursGroup>>();
|
||||
|
|
@ -83,4 +92,26 @@ public class AggregatedHoursGroup {
|
|||
return hoursGroup;
|
||||
}
|
||||
|
||||
public int getHours() {
|
||||
int result = 0;
|
||||
for (HoursGroup each : hoursGroup) {
|
||||
result += each.getWorkingHours();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getCriterionsJoinedByComma() {
|
||||
List<String> criterionNames = asNames(criterions);
|
||||
Collections.sort(criterionNames);
|
||||
return StringUtils.join(criterionNames, ", ");
|
||||
}
|
||||
|
||||
private List<String> asNames(Set<Criterion> criterions) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (Criterion each : criterions) {
|
||||
result.add(each.getName());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,13 +48,11 @@ public class AggregatedHoursGroupTest {
|
|||
|
||||
private Criterion criterion1;
|
||||
private Criterion criterion2;
|
||||
private Criterion criterion3;
|
||||
|
||||
@Before
|
||||
public void setUpCriterions() {
|
||||
criterion1 = createNiceMock(Criterion.class);
|
||||
criterion2 = createNiceMock(Criterion.class);
|
||||
criterion3 = createNiceMock(Criterion.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -76,6 +74,27 @@ public class AggregatedHoursGroupTest {
|
|||
withHours(h4, h5))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHoursReturnTheSumOfAllHours() {
|
||||
HoursGroup h1 = createHoursGroupWithCriterions(criterion1, criterion2);
|
||||
h1.setWorkingHours(10);
|
||||
HoursGroup h2 = createHoursGroupWithCriterions(criterion1, criterion2);
|
||||
h2.setWorkingHours(5);
|
||||
AggregatedHoursGroup aggregate = AggregatedHoursGroup.aggregate(h1, h2)
|
||||
.get(0);
|
||||
assertThat(aggregate.getHours(), equalTo(15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sumAllAggregatedHours() {
|
||||
HoursGroup h1 = createHoursGroupWithCriterions(criterion1, criterion2);
|
||||
h1.setWorkingHours(10);
|
||||
HoursGroup h2 = createHoursGroupWithCriterions(criterion1);
|
||||
h2.setWorkingHours(5);
|
||||
List<AggregatedHoursGroup> list = AggregatedHoursGroup.aggregate(h1, h2);
|
||||
assertThat(AggregatedHoursGroup.sum(list), equalTo(15));
|
||||
}
|
||||
|
||||
private static abstract class AggregatedHoursGroupMatcher extends
|
||||
BaseMatcher<AggregatedHoursGroup> {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue