-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.java
More file actions
87 lines (77 loc) · 2.55 KB
/
FileManager.java
File metadata and controls
87 lines (77 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.io.*;
import java.math.BigInteger;
import java.util.ArrayList;
/**
* Created by niklas on 03.03.17.
*/
public class FileManager {
private String path;
private String[] id;
File[] file;
PrintWriter[] writer;
public FileManager(Body[] body) throws IOException {
path = "/home/niklas/ThreeBody/";
id = new String[body.length];
file = new File[body.length];
writer = new PrintWriter[body.length];
for (int i = 0; i < body.length; i++) {
id[i] = body[i].getId();
file[i] = new File(path + body[i].getId() + ".lvm");
file[i].createNewFile();
writer[i] = new PrintWriter(file[i], "UTF-8");
writer[i].println("#t x1 x2 [x3]");
}
}
public void writeBodyPosition(Body[] body, BigInteger time) {
for (int i = 0; i < body.length; i++) {
writer[i].println(time + " " + body[i].getPosition());
}
}
public void writeComment(String s, String body_id) {
int n = -1;
for (int i = 0; i < id.length; i++) {
if(body_id.equals(id[i])) n=i;
}
writer[n].println("#" + s);
}
public void close() {
for (int i = 0; i < writer.length; i++) {
writer[i].close();
}
}
public Body[] getStartBodys() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("TODO"));
String zeile = reader.readLine();
while (zeile != null) {
//TODO parse strings
zeile = reader.readLine();
}
return null;
}
public static DataSet readFile(File f) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(f));
ArrayList<String> lines = new ArrayList<>();
String zeile = reader.readLine();
while (zeile != null) {
if(zeile.charAt(0)!='#') {
lines.add(zeile);
}
zeile = reader.readLine();
}
int d = lines.get(0).split(" ").length;
String[] n;
double[][] number = new double[lines.size()][d-1];
BigInteger[] time = new BigInteger[lines.size()];
for (int i = 0; i < lines.size(); i++) {
n = lines.get(i).split(" ");
for (int j = 0; j < d; j++) {
if(j==0) {
time[i] = new BigInteger(n[j]);
} else {
number[i][j-1] = Double.valueOf(n[j]);
}
}
}
return new DataSet(time, number);
}
}