]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.history/src/org/simantics/history/csv/ExportInterpolation.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.history / src / org / simantics / history / csv / ExportInterpolation.java
1 package org.simantics.history.csv;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 /**
7  * Specifies the interpolation method to use when producing exported samples in
8  * {@link CSVFormatter}.
9  * 
10  * @author Tuukka Lehtonen
11  * @see CSVFormatter
12  */
13 public enum ExportInterpolation {
14
15         /**
16          * Directly take the last sample whose time stamp is less than or equal to
17          * the sampling time.
18          */
19         PREVIOUS_SAMPLE("Previous sample", "previous"),
20
21         /**
22          * <pre>
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>
26          * </pre>
27          * 
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> &le; t<sub>s</sub> &le;
30          * t<sub>2</sub>.
31          * 
32          * <p>
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>).
35          */
36         LINEAR_INTERPOLATION("Linear interpolation", "lerp");
37
38         public String label;
39         public String preference;
40         ExportInterpolation(String label, String preference) {
41                 this.label = label;
42                 this.preference = preference;
43         }
44         public static List<ExportInterpolation> list() {
45                 return toList(LINEAR_INTERPOLATION, PREVIOUS_SAMPLE);
46         }
47         public static ExportInterpolation fromIndex(int index) {
48                 return list().get(index);
49         }
50         public static ExportInterpolation fromPreference(String preference) {
51                 for(ExportInterpolation s : list()) {
52                         if(s.preference.equals(preference)) return s;
53                 }
54                 return list().get(0);
55         }
56         public int index() {
57                 return list().indexOf(this);
58         }
59         public static ExportInterpolation getDefault() {
60                 return LINEAR_INTERPOLATION;
61         }
62         public String toPreference() {
63                 return preference;
64         }
65         private static <T> List<T> toList(T ... ts) {
66                 ArrayList<T> result = new ArrayList<T>();
67                 for(T t : ts) result.add(t);
68                 return result;
69         }
70 }