ItEr32S12CUAsignacionGrupoRecursosAPlanificacionItEr31S15: Adding method to coalesce intervals

This commit is contained in:
Óscar González Fernández 2009-10-28 19:19:51 +01:00
parent d6e99ca766
commit 517d8a280d

View file

@ -23,8 +23,12 @@
*/
package org.zkoss.ganttz.util;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import org.apache.commons.lang.Validate;
public class Interval {
private final Date start;
@ -79,4 +83,11 @@ public class Interval {
private boolean isIncluded(Date date) {
return start.compareTo(date) <= 0 && finish.compareTo(date) >= 0;
}
public Interval coalesce(Interval otherInterval) {
Validate.notNull(otherInterval);
return new Interval(Collections.min(Arrays.asList(start,
otherInterval.start)), Collections.max(Arrays.asList(finish,
otherInterval.finish)));
}
}