-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask1.java
34 lines (25 loc) · 972 Bytes
/
Task1.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
import java.util.*;
interface Command {
void runCommand();
}
public class Task1 {
public static void main(String[] args) throws Exception {
Map<String, Command> methodMap = new HashMap<String, Command>();
if (args.length == 0)
{
System.out.println("Set command line option ");
return;
}
methodMap.put("h", new Command() {
public void runCommand() { System.out.println("This application is an example of switch replacement "); };
});
methodMap.put("d", new Command() {
public void runCommand() { System.out.println("This is dummy option for test purposes"); };
});
Command defaultCommand = new Command() {
public void runCommand() { System.out.println("Unknown option. Only \"h\" and \"d\" is available "); };
};
String cmd = args[0];
methodMap.getOrDefault(cmd, defaultCommand).runCommand();
}
}