package org.simantics.history.csv; import java.util.ArrayList; import java.util.List; /** * Specifies the interpolation method to use when producing exported samples in * {@link CSVFormatter}. * * @author Tuukka Lehtonen * @see CSVFormatter */ public enum ExportInterpolation { /** * Directly take the last sample whose time stamp is less than or equal to * the sampling time. */ PREVIOUS_SAMPLE("Previous sample", "previous"), /** *
	 * v1               vs                   v2
	 * |----------------|--------------------|
	 * t1               ts                   t2
	 * 
* * Here t1 and t2 are time stamps of those two * successive samples for which t1 ≤ ts ≤ * t2. * *

* The sampling result is then: * vs = v1+(v2-v1)*(ts-t1)/(t2-t1). */ LINEAR_INTERPOLATION("Linear interpolation", "lerp"); public String label; public String preference; ExportInterpolation(String label, String preference) { this.label = label; this.preference = preference; } public static List list() { return toList(LINEAR_INTERPOLATION, PREVIOUS_SAMPLE); } public static ExportInterpolation fromIndex(int index) { return list().get(index); } public static ExportInterpolation fromPreference(String preference) { for(ExportInterpolation s : list()) { if(s.preference.equals(preference)) return s; } return list().get(0); } public int index() { return list().indexOf(this); } public static ExportInterpolation getDefault() { return LINEAR_INTERPOLATION; } public String toPreference() { return preference; } private static List toList(T ... ts) { ArrayList result = new ArrayList(); for(T t : ts) result.add(t); return result; } }