add safeguards
* License, or (at your option) any later version.
*
* MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details.
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with MZmine; if not,
- * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
- * USA
+ * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
*/
package io.github.mzmine.datamodel.data_access;
@@ -51,7 +51,7 @@ public class MobilityScanDataAccess implements MobilityScan {
protected final List<Frame> eligibleFrames;
protected final double[] mzs;
protected final double[] intensities;
-
+ protected final Map<Frame, Integer> frameIndexMap = new HashMap<>();
// current data
protected Frame currentFrame;
protected MobilityScan currentMobilityScan;
@@ -64,8 +64,6 @@ public class MobilityScanDataAccess implements MobilityScan {
protected int currentFrameIndex = -1;
protected int currentSpectrumDatapointIndexOffset = 0;
- protected final Map<Frame, Integer> frameIndexMap = new HashMap<>();
-
/**
* The intended use of this memory access is to loop over all scans and access data points via
* {@link #getMzValue(int)} and {@link #getIntensityValue(int)}
@@ -165,6 +163,10 @@ public class MobilityScanDataAccess implements MobilityScan {
* the current scan
*/
public MobilityScan nextMobilityScan() throws MissingMassListException {
+ if (!hasNextMobilityScan()) {
+ return null;
+ }
+
currentMobilityScanIndex++;
if (currentSpectrum != null) {
// increment by the last mobility scan!
@@ -199,12 +201,16 @@ public class MobilityScanDataAccess implements MobilityScan {
}
/**
- * Sets the next frame. The mobility scan index is reset to -1, therefore {@link
- * #nextMobilityScan} has to be called before accessing new scan data.
+ * Sets the next frame. The mobility scan index is reset to -1, therefore
+ * {@link #nextMobilityScan} has to be called before accessing new scan data.
*
* @return the next Frame.
*/
public Frame nextFrame() {
+ if (!hasNextFrame()) {
+ return null;
+ }
+
currentFrameIndex++;
currentFrame = eligibleFrames.get(currentFrameIndex);
currentNumberOfMobilityScans = currentFrame.getNumberOfMobilityScans();
@@ -326,10 +332,10 @@ public class MobilityScanDataAccess implements MobilityScan {
*/
private int getMaxNumberOfDataPoints(List<Frame> frames) {
return switch (type) {
- case RAW -> frames.stream().mapToInt(Frame::getTotalMobilityScanRawDataPoints).max()
- .orElse(0);
- case CENTROID -> frames.stream().mapToInt(Frame::getTotalMobilityScanMassListDataPoints).max()
- .orElse(0);
+ case RAW ->
+ frames.stream().mapToInt(Frame::getTotalMobilityScanRawDataPoints).max().orElse(0);
+ case CENTROID ->
+ frames.stream().mapToInt(Frame::getTotalMobilityScanMassListDataPoints).max().orElse(0);
};
}
