1 package org.simantics.history.csv;
3 import java.util.ArrayList;
7 * Specifies the interpolation method to use when producing exported samples in
8 * {@link CSVFormatter}.
10 * @author Tuukka Lehtonen
13 public enum ExportInterpolation {
16 * Directly take the last sample whose time stamp is less than or equal to
19 PREVIOUS_SAMPLE("Previous sample", "previous"),
23 * v<sub>1</sub> v<sub>s</sub> v<sub>2</sub>
24 * |----------------|--------------------|
25 * t<sub>1</sub> t<sub>s</sub> t<sub>2</sub>
28 * Here t<sub>1</sub> and t<sub>2</sub> are time stamps of those two
29 * successive samples for which t<sub>1</sub> ≤ t<sub>s</sub> ≤
33 * The sampling result is then:
34 * <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>).
36 LINEAR_INTERPOLATION("Linear interpolation", "lerp");
39 public String preference;
40 ExportInterpolation(String label, String preference) {
42 this.preference = preference;
44 public static List<ExportInterpolation> list() {
45 return toList(LINEAR_INTERPOLATION, PREVIOUS_SAMPLE);
47 public static ExportInterpolation fromIndex(int index) {
48 return list().get(index);
50 public static ExportInterpolation fromPreference(String preference) {
51 for(ExportInterpolation s : list()) {
52 if(s.preference.equals(preference)) return s;
57 return list().indexOf(this);
59 public static ExportInterpolation getDefault() {
60 return LINEAR_INTERPOLATION;
62 public String toPreference() {
65 private static <T> List<T> toList(T ... ts) {
66 ArrayList<T> result = new ArrayList<T>();
67 for(T t : ts) result.add(t);