List<ExecutionCourse> executionCourses) {
List<InfoExecutionCourse> result;
result = (List<InfoExecutionCourse>) CollectionUtils.collect(executionCourses, new Transformer() {
@Override
public Object transform(Object arg0) {
InfoExecutionCourse infoExecutionCourse = null;
infoExecutionCourse = getOccupancyLevels(arg0);
return infoExecutionCourse;
}
private InfoExecutionCourse getOccupancyLevels(Object arg0) {
InfoExecutionCourse infoExecutionCourse;
ExecutionCourse executionCourse = (ExecutionCourse) arg0;
Integer theoreticalCapacity = Integer.valueOf(0);
Integer theoPraticalCapacity = Integer.valueOf(0);
Integer praticalCapacity = Integer.valueOf(0);
Integer labCapacity = Integer.valueOf(0);
Integer doubtsCapacity = Integer.valueOf(0);
Integer reserveCapacity = Integer.valueOf(0);
Integer semCapacity = Integer.valueOf(0);
Integer probCapacity = Integer.valueOf(0);
Integer fieldCapacity = Integer.valueOf(0);
Integer trainCapacity = Integer.valueOf(0);
Integer tutCapacity = Integer.valueOf(0);
Set<Shift> shifts = executionCourse.getAssociatedShifts();
Iterator<Shift> iterator = shifts.iterator();
while (iterator.hasNext()) {
Shift shift = iterator.next();
if (shift.containsType(ShiftType.TEORICA)) {
theoreticalCapacity = Integer.valueOf(theoreticalCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.TEORICO_PRATICA)) {
theoPraticalCapacity = Integer.valueOf(theoPraticalCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.DUVIDAS)) {
doubtsCapacity = Integer.valueOf(doubtsCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.LABORATORIAL)) {
labCapacity = Integer.valueOf(labCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.PRATICA)) {
praticalCapacity = Integer.valueOf(praticalCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.RESERVA)) {
reserveCapacity = Integer.valueOf(reserveCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.SEMINARY)) {
semCapacity = Integer.valueOf(semCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.PROBLEMS)) {
probCapacity = Integer.valueOf(probCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.FIELD_WORK)) {
fieldCapacity = Integer.valueOf(fieldCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.TRAINING_PERIOD)) {
trainCapacity = Integer.valueOf(trainCapacity.intValue() + shift.getLotacao().intValue());
} else if (shift.containsType(ShiftType.TUTORIAL_ORIENTATION)) {
tutCapacity = Integer.valueOf(tutCapacity.intValue() + shift.getLotacao().intValue());
}
}
infoExecutionCourse = InfoExecutionCourse.newInfoFromDomain(executionCourse);
List<Integer> capacities = new ArrayList<Integer>();
if (theoreticalCapacity.intValue() != 0) {
capacities.add(theoreticalCapacity);
}
if (theoPraticalCapacity.intValue() != 0) {
capacities.add(theoPraticalCapacity);
}
if (doubtsCapacity.intValue() != 0) {
capacities.add(doubtsCapacity);
}
if (labCapacity.intValue() != 0) {
capacities.add(labCapacity);
}
if (praticalCapacity.intValue() != 0) {
capacities.add(praticalCapacity);
}
if (reserveCapacity.intValue() != 0) {
capacities.add(reserveCapacity);
}
if (semCapacity.intValue() != 0) {
capacities.add(semCapacity);
}
if (probCapacity.intValue() != 0) {
capacities.add(probCapacity);
}
if (fieldCapacity.intValue() != 0) {
capacities.add(fieldCapacity);
}
if (trainCapacity.intValue() != 0) {
capacities.add(trainCapacity);
}
if (tutCapacity.intValue() != 0) {
capacities.add(tutCapacity);
}
int total = 0;
if (!capacities.isEmpty()) {
total = (Collections.min(capacities)).intValue();
}
if (total == 0) {
infoExecutionCourse.setOccupancy(Double.valueOf(-1));
} else {
infoExecutionCourse.setOccupancy(NumberUtils.formatNumber(
Double.valueOf((Double.valueOf(executionCourse.getAttendsSet().size()).floatValue() * 100 / total)),
1));
}
return infoExecutionCourse;
}