-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
51 lines (40 loc) · 1.34 KB
/
Server.java
File metadata and controls
51 lines (40 loc) · 1.34 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
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Server {
private Scanner file;
private ArrayList<Node> nodes;
public Server() throws FileNotFoundException {
java.io.File filePath = new java.io.File("data.csv");
file = new Scanner(filePath);
nodes = new ArrayList<Node>();
while(hasAnotherLine()){
String line = getline();
String[] stringArray = line.split(",");
int NodeID = Integer.parseInt(stringArray[0]);
int YesID = Integer.parseInt(stringArray[1]);
int NoID = Integer.parseInt(stringArray[2]);
String description = stringArray[3];
String question = stringArray[4];
Node n = new Node();
n.setNodeID(NodeID);
n.setYesID(YesID);
n.setNoID(NoID);
n.setDescription(description);
n.setQuestion(question);
nodes.add(n);
}
Close();
}
public String getline() { return file.nextLine(); }
public void Close(){file.close(); }
public boolean hasAnotherLine() {return file.hasNext(); }
public Node getNode(int NodeID){
for (Node n: nodes){
if (n.getNodeID() == NodeID){
return n;
}
}
return null;
}
}