}
public StageOverviewData view(DateTime aTime, StageOverviewItem anItem) {
Stage[] stages = getMappedStages(anItem.getStages());
DayProgram[] dayPrograms = getFirstRelevantDayPrograms(stages, aTime);
StageOverviewData result = new StageOverviewData();
List<StageOverviewItemData> items = new ArrayList<StageOverviewItemData>();
DateTime minday = getMinDayDate(dayPrograms);
DateTime nextDisplayChange = null;
for (int i = 0; i < dayPrograms.length; i++) {
DayProgram dp = dayPrograms[i];
StageOverviewItemData item = new StageOverviewItemData();
if (dp != null && dp.getDayStart().equals(minday)) {
item.setActive(true);
Show[] relp = dp.getRelevantShows(aTime);
if (relp.length > anItem.getMaxPerformanceCount()) {
relp = Arrays.copyOfRange(relp, 0, anItem.getMaxPerformanceCount());
}
item.setShows(relp);
if (nextDisplayChange == null) {
nextDisplayChange = getNextChange(dp, aTime);
} else {
DateTime dpndch = getNextChange(dp, aTime);
if (dpndch.isBefore(nextDisplayChange)) {
nextDisplayChange = dpndch;
}
}
} else {
item.setActive(false);
item.setShows(new Show[0]);
}
item.setParent(result);
item.setStage(stages[i]);
items.add(item);
}
result.setTime(aTime);
result.setNextDisplayChange(nextDisplayChange);
result.setItems(items.toArray(new StageOverviewItemData[items.size()]));
if (minday != null) {
setStageOverviewDateNotice(minday, result, dayPrograms);
}
return result;
}