-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRead.java
More file actions
57 lines (50 loc) · 1.95 KB
/
Read.java
File metadata and controls
57 lines (50 loc) · 1.95 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
import java.io.*;
import java.util.*;
public class Read {
String queryFile;
String configFile;
Read(String queryFile, String configFile) {
this.queryFile = queryFile;
this.configFile = configFile;
}
public List<List<Double>> qfetch() throws Exception {
//Query.txt
//Open file, create scanner, and list to hold arrays of line tokens
File query = new File(this.queryFile);
Scanner squery = new Scanner(query);
//List<Double[]> lineArray = new ArrayList<Double[]>();
List<List<Double>> lineArray = new ArrayList<List<Double>>();
//Loop through each line, split by space, and create an array
while (squery.hasNextLine()) {
String[] stokens = squery.nextLine().split("\\s+");
//Double[] arrSelec = new Double[stokens.length];
List<Double> arrSelec = new ArrayList<Double>();
for (int i = 0; i < stokens.length; i++) {
double selec = Double.parseDouble(stokens[i]);
//arrSelec[i] = selec;
arrSelec.add(selec);
}
//Insert array into global array list
lineArray.add(arrSelec);
}
//Close file to prevent memory leak
squery.close();
return lineArray;
}
public Map<String, Double> cfetch() throws Exception {
//Config.txt
//Open file, create scanner, and Map
File config = new File(this.configFile);
Scanner sconfig = new Scanner(config);
Map<String, Double> configMap = new HashMap<String, Double>();
//Loop through each line, split by equal sign, and add to Map
while (sconfig.hasNextLine()) {
String[] ctokens = sconfig.nextLine().split(" = ");
double cost = Double.parseDouble(ctokens[1]);
configMap.put(ctokens[0],cost);
}
//Close file tp provent memory leak
sconfig.close();
return configMap;
}
}