LCB
This commit is contained in:
@ -4,12 +4,23 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ConfigParser {
|
||||
|
||||
private String path;
|
||||
|
||||
private int messages;
|
||||
private final ConcurrentHashMap<Integer,List<Integer>> causality = new ConcurrentHashMap<>();
|
||||
|
||||
public ConfigParser(List<Host> hosts) {
|
||||
for (Host host : hosts) {
|
||||
causality.put(host.getId(),new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean populate(String value) {
|
||||
@ -17,14 +28,22 @@ public class ConfigParser {
|
||||
path = file.getPath();
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
|
||||
int lineNum = 1;
|
||||
int lineNum = 0;
|
||||
for (String line; (line = br.readLine()) != null; lineNum++) {
|
||||
switch(lineNum){
|
||||
case 1:
|
||||
messages = Integer.parseInt(line);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
System.out.println(line);
|
||||
String[] lparts = line.trim().split(" ");
|
||||
if (lineNum == 0){
|
||||
messages = Integer.parseInt(lparts[0]);
|
||||
}else if (lineNum>=1 && lineNum<=causality.keySet().size()){
|
||||
Integer hid = Integer.parseInt(lparts[0]);
|
||||
List<Integer> vl = causality.get(hid);
|
||||
if(vl != null){
|
||||
for(int i = 1; i < lparts.length; ++i){
|
||||
vl.add(Integer.parseInt(lparts[i]));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -41,4 +60,8 @@ public class ConfigParser {
|
||||
public int getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public Map<Integer, List<Integer>> getCausality() {
|
||||
return causality;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cs451.parser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Parser {
|
||||
|
||||
@ -57,8 +58,9 @@ public class Parser {
|
||||
}
|
||||
|
||||
if (argsNum == Constants.ARG_LIMIT_CONFIG) {
|
||||
configParser = new ConfigParser();
|
||||
configParser = new ConfigParser(hosts());
|
||||
if (!configParser.populate(args[Constants.CONFIG_VALUE])) {
|
||||
help();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,4 +110,8 @@ public class Parser {
|
||||
return configParser.getMessages();
|
||||
}
|
||||
|
||||
public Map<Integer, List<Integer>> causality(){
|
||||
return configParser.getCausality();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user