Source:
<code>private double InterpolationX(List<Triplet> horizontalSlice, int mu, double halfHeight, int leftBound, int rightBound, int roundedmz, Direction direction) { int i = mu; Double Y1 = null; <START> Double Y2 = null; <END> int step = direction == Direction.RIGHT ? 1 : -1; Comparator<Triplet> compareScanMz = new Comparator<Triplet>() { @Override public int compare(Triplet o1, Triplet o2) { int scan1 = o1.scanNumber; int scan2 = o2.scanNumber; int scanCompare = Integer.compare(scan1, scan2); if (scanCompare != 0) { return scanCompare; } else { int mz1 = o1.mz; int mz2 = o2.mz; return Integer.compare(mz1, mz2); } } }; Collections.sort(horizontalSlice, compareScanMz); while (leftBound <= i && i <= rightBound) { i += step; Triplet searchTriplet1 = new Triplet(); searchTriplet1.mz = roundedmz; searchTriplet1.scanNumber = i; int index1 = Collections.binarySearch(horizontalSlice, searchTriplet1, compareScanMz); if (index1 >= 0) { SliceSparseMatrix.Triplet triplet1 = horizontalSlice.get(index1); if (triplet1.intensity != 0 && triplet1.intensity < halfHeight) { Triplet searchTriplet2 = new Triplet(); searchTriplet2.mz = roundedmz; searchTriplet2.scanNumber = i - step; Y1 = (double) triplet1.intensity; int index2 = Collections.binarySearch(horizontalSlice, searchTriplet2, compareScanMz); if (index2 >= 0) { SliceSparseMatrix.Triplet triplet2 = horizontalSlice.get(index2); if (triplet2.intensity != 0) { Y2 = (double) triplet2.intensity; break; } } } } } if (Y1 == null || Y2 == null) throw new IllegalArgumentException("Cannot find BiGaussian."); double X = ((halfHeight - Y1) * ((i - step) - i) / (Y2 - Y1)) + i; return X; }</code><technical_language>Instead of null Doubles set, I suggest keeping double initializing Double.NaN</technical_language>

Target:
private double InterpolationX(List<Triplet> horizontalSlice, int mu, double halfHeight, int leftBound, int rightBound, int roundedmz, Direction direction) { int i = mu; double Y1 = Double.NaN; double Y2 = Double.NaN; int step = direction == Direction.RIGHT ? 1 : -1; Comparator<Triplet> compareScanMz = new Comparator<Triplet>() { @Override public int compare(Triplet o1, Triplet o2) { int scan1 = o1.scanNumber; int scan2 = o2.scanNumber; int scanCompare = Integer.compare(scan1, scan2); if (scanCompare != 0) { return scanCompare; } else { int mz1 = o1.mz; int mz2 = o2.mz; return Integer.compare(mz1, mz2); } } }; Collections.sort(horizontalSlice, compareScanMz); while (leftBound <= i && i <= rightBound) { i += step; Triplet searchTriplet1 = new Triplet(); searchTriplet1.mz = roundedmz; searchTriplet1.scanNumber = i; int index1 = Collections.binarySearch(horizontalSlice, searchTriplet1, compareScanMz); if (index1 >= 0) { SliceSparseMatrix.Triplet triplet1 = horizontalSlice.get(index1); if (triplet1.intensity != 0 && triplet1.intensity < halfHeight) { Triplet searchTriplet2 = new Triplet(); searchTriplet2.mz = roundedmz; searchTriplet2.scanNumber = i - step; Y1 = (double) triplet1.intensity; int index2 = Collections.binarySearch(horizontalSlice, searchTriplet2, compareScanMz); if (index2 >= 0) { SliceSparseMatrix.Triplet triplet2 = horizontalSlice.get(index2); if (triplet2.intensity != 0) { Y2 = (double) triplet2.intensity; break; } } } } } if (Y1 == Double.NaN || Y2 == Double.NaN) throw new IllegalArgumentException("Cannot find BiGaussian."); double X = ((halfHeight - Y1) * ((i - step) - i) / (Y2 - Y1)) + i; return X; }