diff --git a/WebApp/src/uk/ac/exeter/QuinCe/data/Dataset/DatasetMeasurements.java b/WebApp/src/uk/ac/exeter/QuinCe/data/Dataset/DatasetMeasurements.java index 16f8f0d4f..7a5f46ac6 100644 --- a/WebApp/src/uk/ac/exeter/QuinCe/data/Dataset/DatasetMeasurements.java +++ b/WebApp/src/uk/ac/exeter/QuinCe/data/Dataset/DatasetMeasurements.java @@ -208,23 +208,43 @@ public TreeSet getMeasurementsInSameRun(long variableId, public TreeSet getRunBefore(long variableId, String runType, LocalDateTime time) { - Optional lastBefore = getMeasurements(variableId, runType) - .stream().filter(m -> m.getTime().isBefore(time)) - .reduce((first, second) -> second); + TreeSet result; - return lastBefore.isEmpty() ? new TreeSet() - : getMeasurementsInSameRun(variableId, lastBefore.get()); + List measurements = getMeasurements(variableId, runType); + if (null == measurements) { + result = new TreeSet(); + } else { + + Optional lastBefore = getMeasurements(variableId, runType) + .stream().filter(m -> m.getTime().isBefore(time)) + .reduce((first, second) -> second); + + result = lastBefore.isEmpty() ? new TreeSet() + : getMeasurementsInSameRun(variableId, lastBefore.get()); + } + + return result; } public TreeSet getRunAfter(long variableId, String runType, LocalDateTime time) { - Optional firstAfter = getMeasurements(variableId, runType) - .stream().filter(m -> m.getTime().isAfter(time)).findFirst(); + TreeSet result; - return firstAfter.isEmpty() ? new TreeSet() - : getMeasurementsInSameRun(variableId, firstAfter.get()); + List measurements = getMeasurements(variableId, runType); + + if (null == measurements) { + result = new TreeSet(); + } else { + Optional firstAfter = getMeasurements(variableId, runType) + .stream().filter(m -> m.getTime().isAfter(time)).findFirst(); + + result = firstAfter.isEmpty() ? new TreeSet() + : getMeasurementsInSameRun(variableId, firstAfter.get()); + } + + return result; }