diff --git a/core/src/main/java/info/openrocket/core/simulation/DataBranch.java b/core/src/main/java/info/openrocket/core/simulation/DataBranch.java new file mode 100644 index 000000000..8f1e6cae8 --- /dev/null +++ b/core/src/main/java/info/openrocket/core/simulation/DataBranch.java @@ -0,0 +1,71 @@ +package info.openrocket.core.simulation; + +import info.openrocket.core.util.Monitorable; + +import java.util.List; + +/** + * A branch of data / collection of data points for a specific type of data. + * @param the type of data in this branch + */ +public interface DataBranch extends Monitorable { + /** + * Return an array of values for the specified variable type. + * + * @param type the variable type. + * @return a list of the variable values, or null if + * the variable type hasn't been added to this branch. + */ + List get(T type); + + /** + * Return the value of the specified type at the specified index. + * @param type the variable type + * @param index the data index of the value + * @return the value at the specified index + */ + Double getByIndex(T type, int index); + + /** + * Return the last value of the specified type in the branch, or NaN if the type is + * unavailable. + * + * @param type the parameter type. + * @return the last value in this branch, or NaN. + */ + double getLast(T type); + + /** + * Return the minimum value of the specified type in the branch, or NaN if the type + * is unavailable. + * + * @param type the parameter type. + * @return the minimum value in this branch, or NaN. + */ + double getMinimum(T type); + + /** + * Return the maximum value of the specified type in the branch, or NaN if the type + * is unavailable. + * + * @param type the parameter type. + * @return the maximum value in this branch, or NaN. + */ + double getMaximum(T type); + + /** + * Return the number of data points in this branch. + */ + int getLength(); + + /** + * Return the variable types included in this branch. The types are sorted in their + * natural order. + */ + T[] getTypes(); + + /** + * Return the branch name. + */ + String getName(); +} diff --git a/core/src/main/java/info/openrocket/core/simulation/DataType.java b/core/src/main/java/info/openrocket/core/simulation/DataType.java new file mode 100644 index 000000000..99e5b5738 --- /dev/null +++ b/core/src/main/java/info/openrocket/core/simulation/DataType.java @@ -0,0 +1,9 @@ +package info.openrocket.core.simulation; + +import info.openrocket.core.util.UnitValue; + +/** + * A type of data that can be stored in a {@link DataBranch}. + */ +public interface DataType extends UnitValue { +} diff --git a/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java b/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java index 10fdd1147..e866abc9e 100644 --- a/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java +++ b/core/src/main/java/info/openrocket/core/simulation/FlightDataBranch.java @@ -29,7 +29,7 @@ import info.openrocket.core.util.Mutable; * * @author Sampo Niskanen */ -public class FlightDataBranch implements Monitorable { +public class FlightDataBranch implements DataBranch { /** The name of this flight data branch. */ private final String name; @@ -228,26 +228,19 @@ public class FlightDataBranch implements Monitorable { } } - /** - * Return the branch name. - */ + @Override public String getName() { return name; } - /** - * Return the variable types included in this branch. The types are sorted in their - * natural order. - */ + @Override public FlightDataType[] getTypes() { FlightDataType[] array = values.keySet().toArray(new FlightDataType[0]); Arrays.sort(array); return array; } - /** - * Return the number of data points in this branch. - */ + @Override public int getLength() { for (ArrayList doubles : values.values()) { return doubles.size(); @@ -255,13 +248,7 @@ public class FlightDataBranch implements Monitorable { return 0; } - /** - * Return an array of values for the specified variable type. - * - * @param type the variable type. - * @return a list of the variable values, or null if - * the variable type hasn't been added to this branch. - */ + @Override public List get(FlightDataType type) { ArrayList list = values.get(type); if (list == null) @@ -269,12 +256,7 @@ public class FlightDataBranch implements Monitorable { return list.clone(); } - /** - * Return the value of the specified type at the specified index. - * @param type the variable type - * @param index the data index of the value - * @return the value at the specified index - */ + @Override public Double getByIndex(FlightDataType type, int index) { if (index < 0 || index >= getLength()) { throw new IllegalArgumentException("Index out of bounds"); @@ -286,13 +268,7 @@ public class FlightDataBranch implements Monitorable { return list.get(index); } - /** - * Return the last value of the specified type in the branch, or NaN if the type is - * unavailable. - * - * @param type the parameter type. - * @return the last value in this branch, or NaN. - */ + @Override public double getLast(FlightDataType type) { ArrayList list = values.get(type); if (list == null || list.isEmpty()) @@ -300,13 +276,7 @@ public class FlightDataBranch implements Monitorable { return list.get(list.size() - 1); } - /** - * Return the minimum value of the specified type in the branch, or NaN if the type - * is unavailable. - * - * @param type the parameter type. - * @return the minimum value in this branch, or NaN. - */ + @Override public double getMinimum(FlightDataType type) { Double v = minValues.get(type); if (v == null) @@ -314,13 +284,7 @@ public class FlightDataBranch implements Monitorable { return v; } - /** - * Return the maximum value of the specified type in the branch, or NaN if the type - * is unavailable. - * - * @param type the parameter type. - * @return the maximum value in this branch, or NaN. - */ + @Override public double getMaximum(FlightDataType type) { Double v = maxValues.get(type); if (v == null) diff --git a/core/src/main/java/info/openrocket/core/simulation/FlightDataType.java b/core/src/main/java/info/openrocket/core/simulation/FlightDataType.java index 91744034e..ad9449236 100644 --- a/core/src/main/java/info/openrocket/core/simulation/FlightDataType.java +++ b/core/src/main/java/info/openrocket/core/simulation/FlightDataType.java @@ -34,7 +34,7 @@ import info.openrocket.core.util.StringUtils; * * @author Sampo Niskanen */ -public class FlightDataType implements Comparable, Groupable, UnitValue { +public class FlightDataType implements Comparable, Groupable, DataType { private static final Translator trans = Application.getTranslator(); private static final Logger log = LoggerFactory.getLogger(FlightDataType.class); @@ -490,10 +490,12 @@ public class FlightDataType implements Comparable, Groupable