-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.java
More file actions
71 lines (58 loc) · 1.84 KB
/
Command.java
File metadata and controls
71 lines (58 loc) · 1.84 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
69
70
71
package zipcode;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public enum Command {
CLASSNEW("classcreate"){
public void execute(String[] args) {
final Path filePath = Path.of("./","ClassTempl.txt");
String templ;
try {
templ = Files.readString(filePath);
String classname = args[0];
String classfilename = classname+".java";
PrintWriter result = new PrintWriter(classfilename);
result.printf(templ, classname, classname);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
},
ERR("error"){
public void execute(String[] args) {
}
},
;
public static Command getOp(String string) {
return null;
}
abstract void execute(String[] args);
private String name;
private static Boolean _DEBUG = false;
private static final Map<String,Command> ENUM_MAP;
Command (String name) {
this.name = name;
}
public String getName() {
return this.name;
}
// Build an immutable map of String name to enum pairs.
// Any Map impl can be used.
static {
Map<String,Command> map = new ConcurrentHashMap<String, Command>();
for (Command instance : Command.values()) {
map.put(instance.getName().toLowerCase(),instance);
}
ENUM_MAP = Collections.unmodifiableMap(map);
}
public static Command get (String name) {
return ENUM_MAP.getOrDefault(name.toLowerCase(), Command.ERR);
}
}