added convenience methods to PlotModuleCombo
package net.sf.mzmine.modules.datapointprocessing;
+import java.util.ArrayList;
import java.util.List;
+import javax.annotation.Nonnull;
+import io.github.msdk.MSDKRuntimeException;
import net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot;
public class PlotModuleCombo {
@@ -12,10 +15,21 @@ public class PlotModuleCombo {
setModules(modules);
}
+ public PlotModuleCombo() {
+ modules = new ArrayList<Class<DataPointProcessingModule>>();
+ }
+
+ public boolean plotValid() {
+ return (plot != null);
+ }
+
public SpectraPlot getPlot() {
+ if (!plotValid())
+ throw new MSDKRuntimeException("getPlot() called, although plot == null");
return plot;
}
+ @Nonnull
public List<Class<DataPointProcessingModule>> getModules() {
return modules;
}
@@ -28,6 +42,16 @@ public class PlotModuleCombo {
this.modules = modules;
}
+ /**
+ *
+ * @return Returns true if the module list is initialized and > 0.
+ */
+ public boolean modulesValid() {
+ if(modules != null && modules.size() > 0)
+ return true;
+ return false;
+ }
+
public boolean addModule(Class<DataPointProcessingModule> module) {
return this.modules.add(module);
}
@@ -35,4 +59,43 @@ public class PlotModuleCombo {
public boolean removeTask(Class<DataPointProcessingModule> module) {
return this.modules.remove(module);
}
+
+ /**
+ *
+ * @param current A pointer to the current module.
+ * @return Returns true if there is one or more modules, false if not.
+ */
+ public boolean hasNextModule(Class<DataPointProcessingModule> current) {
+ if (modules.contains(current)) {
+ int index = modules.indexOf(current);
+ if (modules.size() < index + 1) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param current A pointer to the current module.
+ * @return Returns the next module in this PlotModuleCombo. If this pmc has no next module the
+ * return is null. Use hasNextModule to check beforehand.
+ */
+ public Class<DataPointProcessingModule> getNextModule(Class<DataPointProcessingModule> current) {
+ if (hasNextModule(current))
+ return modules.get(modules.indexOf(current) + 1);
+ return null;
+ }
+
+ /**
+ *
+ * @return Returns the first module in this PlotModuleCombo. If the list of modules is not
+ * initialised, the return is null.
+ */
+ public Class<DataPointProcessingModule> getFirstModule() {
+ if (modules.size() > 0) {
+ return modules.get(0);
+ }
+ return null;
+ }
}
