public GanttDate getEnd() { GanttDate result = getEndPeriod(); for (LoadTimeLine loadTimeLine : getChildren()) { GanttDate end = loadTimeLine.getEnd(); if (end != null) { result = result == null || result.compareTo(end) < 0 ? end : result; } } return result; }
public GanttDate getStart() { GanttDate result = getStartPeriod(); for (LoadTimeLine loadTimeLine : getChildren()) { GanttDate start = loadTimeLine.getStart(); if (start != null) { result = result == null || result.compareTo(start) > 0 ? start : result; } } return result; }
private void givenValidLoadTimeLine() { conceptName = "bla"; loadTimeLine = new LoadTimeLine( conceptName, Arrays.asList( new LoadPeriod( GanttDate.createFrom(new LocalDate(2009, 10, 5)), GanttDate.createFrom(new LocalDate(2009, 10, 11)), "100", "20", new LoadLevel(20))), null); }
@Test(expected = IllegalArgumentException.class) public void theLoadPeriodsMustNotOverlap() { LoadPeriod l1 = new LoadPeriod( GanttDate.createFrom(new LocalDate(2009, 10, 5)), GanttDate.createFrom(new LocalDate(2009, 10, 11)), "100", "20", new LoadLevel(20)); LoadPeriod l2 = new LoadPeriod( GanttDate.createFrom(new LocalDate(2009, 5, 3)), GanttDate.createFrom(new LocalDate(2009, 10, 10)), "100", "20", new LoadLevel(20)); new LoadTimeLine("bla", Arrays.asList(l1, l2), null); }
private static GanttDate min(GanttDate one, GanttDate other) { if (one == null) { return other; } if (other == null) { return one; } return one.compareTo(other) < 0 ? one : other; }
public static Interval getIntervalFrom(List<LoadTimeLine> timeLines) { GanttDate start = null; GanttDate end = null; for (LoadTimeLine loadTimeLine : timeLines) { if (!loadTimeLine.isEmpty()) { Validate.notNull(loadTimeLine.getStart()); start = min(start, loadTimeLine.getStart()); Validate.notNull(loadTimeLine.getEnd()); end = max(end, loadTimeLine.getEnd()); } } if (timeLines.isEmpty() || start == null || end == null) { LocalDate localDateNow = new LocalDate(); return new Interval(localDateNow, localDateNow.plusYears(5)); } return new Interval(start.toLocalDate(), end.asExclusiveEnd()); }
@Test public void aLoadTimelineSortsItsReceivedPeriods() { LoadPeriod l1 = new LoadPeriod( GanttDate.createFrom(new LocalDate(2009, 10, 5)), GanttDate.createFrom(new LocalDate(2009, 10, 11)), "100", "20", new LoadLevel(20)); LoadPeriod l2 = new LoadPeriod( GanttDate.createFrom(new LocalDate(2009, 5, 3)), GanttDate.createFrom(new LocalDate(2009, 6, 3)), "100", "20", new LoadLevel(20)); LoadTimeLine loadTimeLine = new LoadTimeLine("bla", Arrays.asList(l1, l2), null); List<LoadPeriod> loadPeriods = loadTimeLine.getLoadPeriods(); assertThat(loadPeriods.get(0), sameInstance(l2)); assertThat(loadPeriods.get(1), sameInstance(l1)); }