-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationReader.java
More file actions
executable file
·68 lines (59 loc) · 1.42 KB
/
ConfigurationReader.java
File metadata and controls
executable file
·68 lines (59 loc) · 1.42 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
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class ConfigurationReader{
File file;
Scanner sc;
String fileName;
public ConfigurationReader(String fileName) throws IOException{
file = new File(fileName);
sc = new Scanner(file);
String nextLine;
}
public String[] getEntries(){
String entries[];
String line = "";
while(line.equals("") || isComment(line) == true){
line = nextLine();
}
entries = splitLine(line);
return entries;
}
public String[] splitLine(String line){
List<String> partsList = new ArrayList<String>();
Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");
Matcher matcher = regex.matcher(line);
while(matcher.find()){
partsList.add(matcher.group().replace("\"", ""));
}
String[] parts = new String[partsList.size()];
for (int i =0; i < partsList.size(); i++){
parts[i] = partsList.get(i);
}
return parts;
}
public Boolean hasMoreLines(){
if(sc.hasNextLine()){
return true;
}else{
return false;
}
}
public String nextLine(){
String line = sc.nextLine();
return line;
}
public Boolean isComment(String line){
Character firstLetter = Character.valueOf(line.charAt(0));
if(firstLetter == '#' ){
return true;
}else{
return false;
}
}
}