]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.history/src/org/simantics/history/csv/ExportInterpolation.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.history / src / org / simantics / history / csv / ExportInterpolation.java
diff --git a/bundles/org.simantics.history/src/org/simantics/history/csv/ExportInterpolation.java b/bundles/org.simantics.history/src/org/simantics/history/csv/ExportInterpolation.java
new file mode 100644 (file)
index 0000000..b0cad53
--- /dev/null
@@ -0,0 +1,70 @@
+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> &le; t<sub>s</sub> &le;\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