ItEr49S10CUVisualizacionResponsabilidadesTRaballoNaPlanificacionItEr48S10: Adding max combiner

This commit is contained in:
Óscar González Fernández 2010-03-06 17:27:01 +01:00
parent c1307d8acd
commit 0091ffbf3e

View file

@ -20,7 +20,9 @@
package org.navalplanner.business.calendars.entities;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.Validate;
@ -31,11 +33,11 @@ public abstract class CombinedWorkHours implements IWorkHours {
private final List<IWorkHours> workHours;
public CombinedWorkHours(List<IWorkHours> workHours) {
public CombinedWorkHours(Collection<? extends IWorkHours> workHours) {
Validate.notNull(workHours);
Validate.noNullElements(workHours);
Validate.isTrue(!workHours.isEmpty());
this.workHours = workHours;
this.workHours = new ArrayList<IWorkHours>(workHours);
}
public static CombinedWorkHours minOf(IWorkHours... workHours) {
@ -43,6 +45,15 @@ public abstract class CombinedWorkHours implements IWorkHours {
return new Min(Arrays.asList(workHours));
}
public static CombinedWorkHours maxOf(IWorkHours... workHours) {
return maxOf(Arrays.asList(workHours));
}
public static CombinedWorkHours maxOf(
Collection<? extends IWorkHours> workHours) {
return new Max(workHours);
}
@Override
public Integer getCapacityAt(LocalDate date) {
Integer current = null;
@ -110,3 +121,26 @@ class Min extends CombinedWorkHours {
}
}
class Max extends CombinedWorkHours {
public Max(Collection<? extends IWorkHours> workHours) {
super(workHours);
}
@Override
protected Integer updateCapacity(Integer current, Integer each) {
return Math.max(current, each);
}
@Override
protected Integer updateHours(Integer current, Integer each) {
return Math.max(current, each);
}
@Override
protected AvailabilityTimeLine compoundAvailability(
AvailabilityTimeLine accumulated, AvailabilityTimeLine each) {
return accumulated.or(each);
}
}