-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewer.java
More file actions
77 lines (61 loc) · 2.19 KB
/
Copy pathViewer.java
File metadata and controls
77 lines (61 loc) · 2.19 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
72
73
74
75
76
77
package jp.co.training;
import static jp.co.training.Const.*;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import jp.co.training.book.ItemCode;
import jp.co.training.command.CommandResult;
import jp.co.training.common.Code;
import jp.co.training.common.Status;
public class Viewer {
private ResourceBundle rbMessages;
// メッセージ定義ファイルのキー
private static final String PROMPT_KEY = "prompt";
private static final String END_MESSAGE_KEY = "end.message";
//メッセージ定義ファイルのパス
private static final String MESSAGES_RESOURCE = "messages";
public Viewer() {
try {
rbMessages = ResourceBundle.getBundle(MESSAGES_RESOURCE);
} catch (MissingResourceException e) {
System.out.println("ERROR: cannnot find message file.");
System.exit(1);
}
}
public void promptMessages() {
System.out.print(rbMessages.containsKey(PROMPT_KEY) ? rbMessages.getString(PROMPT_KEY) : "books>");
}
public void endMessages() {
System.out.print(rbMessages.containsKey(END_MESSAGE_KEY) ? rbMessages.getString(PROMPT_KEY) : "bye.");
}
public void commandMessages(CommandResult commandResult) {
if (commandResult.getStatus() == Status.OK) {
standardMessages(commandResult.getCommandName());
} else {
errorMessages(commandResult.getCodes());
errorMessages(commandResult.getItemCodes());
}
}
public void standardMessages(String commandName) {
switch (commandName) {
case INSERT:
System.out.println("inserted");
break;
default:
}
}
public void errorMessages(Map<String, Set<ItemCode>> itemCodes) {
for (Map.Entry<String, Set<ItemCode>> entry : itemCodes.entrySet()) {
System.out.println(entry.getKey());
for (ItemCode code : entry.getValue()) {
System.out.println(code);
}
}
}
public void errorMessages(Set<Code> codes) {
for (Code code : codes) {
System.out.println(code);
}
}
}