Skip to content

Commit

Permalink
Fix another null exception when retrieving min positions
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Mar 28, 2023
1 parent 143a4f9 commit ab9f961
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

import static ome.formats.model.UnitsFactory.convertTime;

Expand Down Expand Up @@ -108,7 +105,6 @@ public static Time computeMeanExposureTime(Iterable<? extends PlaneInfoWrapper>
Iterator<? extends PlaneInfoWrapper> iterator = planesInfo.iterator();
while (t == null && iterator.hasNext()) {
t = convertTime(planesInfo.iterator().next().getExposureTime());
iterator.next();
}

Unit<ome.units.quantity.Time> unit = t == null ? UNITS.SECOND : t.unit();
Expand All @@ -119,7 +115,10 @@ public static Time computeMeanExposureTime(Iterable<? extends PlaneInfoWrapper>
if (channel == plane.getTheC()) {
ome.units.quantity.Time time = convertTime(plane.getExposureTime());
if (time != null) {
mean += time.value(unit).doubleValue();
Number value = time.value(unit);
if (value != null) {
mean += value.doubleValue();
}
count++;
}
}
Expand All @@ -141,13 +140,15 @@ public static Time computeMeanExposureTime(Iterable<? extends PlaneInfoWrapper>
public static Length getMinPosition(Collection<? extends PlaneInfoWrapper> planesInfo,
Function<? super PlaneInfoWrapper, ? extends Length> getter,
Unit<ome.units.quantity.Length> unit) {
List<Double> positions = planesInfo.stream()
.map(getter)
.map(UnitsFactory::convertLength)
.filter(Objects::nonNull)
.map(p -> p.value(unit).doubleValue())
.collect(Collectors.toList());
Double pos = positions.isEmpty() ? 0.0d : Collections.min(positions);
double pos = planesInfo.stream()
.map(getter)
.map(UnitsFactory::convertLength)
.filter(Objects::nonNull)
.map(p -> p.value(unit))
.filter(Objects::nonNull)
.mapToDouble(Number::doubleValue)
.min()
.orElse(0.0d);
return new LengthI(pos, unit);
}

Expand Down

0 comments on commit ab9f961

Please sign in to comment.