--- /dev/null
+package org.simantics.history.csv;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+/**\r
+ * Specifies the interpolation method to use when producing exported samples in\r
+ * {@link CSVFormatter}.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * @see CSVFormatter\r
+ */\r
+public enum ExportInterpolation {\r
+\r
+ /**\r
+ * Directly take the last sample whose time stamp is less than or equal to\r
+ * the sampling time.\r
+ */\r
+ PREVIOUS_SAMPLE("Previous sample", "previous"),\r
+\r
+ /**\r
+ * <pre>\r
+ * v<sub>1</sub> v<sub>s</sub> v<sub>2</sub>\r
+ * |----------------|--------------------|\r
+ * t<sub>1</sub> t<sub>s</sub> t<sub>2</sub>\r
+ * </pre>\r
+ * \r
+ * Here t<sub>1</sub> and t<sub>2</sub> are time stamps of those two\r
+ * successive samples for which t<sub>1</sub> ≤ t<sub>s</sub> ≤\r
+ * t<sub>2</sub>.\r
+ * \r
+ * <p>\r
+ * The sampling result is then:\r
+ * <code>v<sub>s</sub> = v<sub>1</sub>+(v<sub>2</sub>-v<sub>1</sub>)*(t<sub>s</sub>-t<sub>1</sub>)/(t<sub>2</sub>-t<sub>1</sub>).\r
+ */\r
+ LINEAR_INTERPOLATION("Linear interpolation", "lerp");\r
+\r
+ public String label;\r
+ public String preference;\r
+ ExportInterpolation(String label, String preference) {\r
+ this.label = label;\r
+ this.preference = preference;\r
+ }\r
+ public static List<ExportInterpolation> list() {\r
+ return toList(LINEAR_INTERPOLATION, PREVIOUS_SAMPLE);\r
+ }\r
+ public static ExportInterpolation fromIndex(int index) {\r
+ return list().get(index);\r
+ }\r
+ public static ExportInterpolation fromPreference(String preference) {\r
+ for(ExportInterpolation s : list()) {\r
+ if(s.preference.equals(preference)) return s;\r
+ }\r
+ return list().get(0);\r
+ }\r
+ public int index() {\r
+ return list().indexOf(this);\r
+ }\r
+ public static ExportInterpolation getDefault() {\r
+ return LINEAR_INTERPOLATION;\r
+ }\r
+ public String toPreference() {\r
+ return preference;\r
+ }\r
+ private static <T> List<T> toList(T ... ts) {\r
+ ArrayList<T> result = new ArrayList<T>();\r
+ for(T t : ts) result.add(t);\r
+ return result;\r
+ }\r
+}\r