From 0091ffbf3e4a9c8d14d3890bf79804adebe25913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Sat, 6 Mar 2010 17:27:01 +0100 Subject: [PATCH] ItEr49S10CUVisualizacionResponsabilidadesTRaballoNaPlanificacionItEr48S10: Adding max combiner --- .../calendars/entities/CombinedWorkHours.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CombinedWorkHours.java b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CombinedWorkHours.java index 876396c3d..fd310050a 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CombinedWorkHours.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/calendars/entities/CombinedWorkHours.java @@ -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 workHours; - public CombinedWorkHours(List workHours) { + public CombinedWorkHours(Collection workHours) { Validate.notNull(workHours); Validate.noNullElements(workHours); Validate.isTrue(!workHours.isEmpty()); - this.workHours = workHours; + this.workHours = new ArrayList(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 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 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); + } +}