forked from apache/tomee-tck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sections.java
73 lines (56 loc) · 1.87 KB
/
Sections.java
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
import java.io.IOException;
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.List;
import java.util.ArrayList;
/**
* @version $Rev$ $Date$
*/
public class Sections {
public static void main(String[] args) throws Exception {
if (args.length != 2){
System.err.println("args: <current> <sectionsFile>");
}
complete(args[0], args[1]);
}
public static void complete(String cur, String sectionsFile) throws IOException {
List<String> options = new ArrayList();
String[] parts = cur.split("\\.");
File file = new File(sectionsFile);
FileReader fileReader = new FileReader(file);
BufferedReader in = new BufferedReader(fileReader);
String section = in.readLine();
boolean moreOptions = false;
while (section != null){
try {
if (!section.startsWith(cur)) continue;
String[] p = section.split("\\.");
int pos = parts.length + 1;
if (!cur.endsWith(".")){
pos--;
}
String packge = "";
for (int i = 0; i < p.length && i < pos; i++) {
String s = p[i];
packge += s;
if (!section.equals(packge)){
packge += ".";
}
}
if (!section.equals(packge)){
moreOptions = true;
}
if (!options.contains(packge)) options.add(packge);
} finally {
section = in.readLine();
}
}
if (moreOptions && options.size() > 0){
options.add(options.get(options.size()-1)+"...");
}
for (String s : options) {
System.out.println(s);
}
}
}