Last active
November 28, 2016 15:51
-
-
Save miho/e9dcf8a82ee3f6211e3a315948d11801 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.mihosoft.vrl.user; | |
import eu.mihosoft.vrl.user.VectorTrajectory; | |
@ComponentInfo(name="VectorTrajectoryToFile", category="JFreeChart") | |
public class VectorTrajectoryToFile implements java.io.Serializable { | |
private static final long serialVersionUID=1L; | |
public void toFile( | |
@ParamInfo(name="VectorTrajectory", style="default", options="") VectorTrajectory vt, | |
@ParamInfo(name="", style="save-dialog", options="") File file) { | |
file.newWriter().withWriter{w-> | |
for(double[] line : vt) { | |
String s = "" | |
for(double entry : line) { | |
s += entry + "\t"; | |
} | |
w << s << "\n" | |
} | |
} | |
} | |
@OutputInfo(name="VectorTrajectory") | |
public VectorTrajectory fromFile( | |
@ParamInfo(name="", style="load-dialog", options="") File file) { | |
VectorTrajectory vt = new VectorTrajectory(); | |
def line | |
file.withReader { reader -> | |
while ((line = reader.readLine())!=null) { | |
String[] entries = line.split("\\s"); | |
double[] numbers = new double[entries.length] | |
for (int i = 0; i < numbers.length; i++) { | |
numbers[i] = Double.parseDouble(entries[i]) | |
} | |
vt.add(numbers) | |
} | |
} | |
return vt | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment