Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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