1
2
3
4
5 package gboat2.base.bridge.model;
6
7 import java.io.Serializable;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.LinkedList;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.Set;
14
15
16
17
18
19
20 public class Priority implements Serializable {
21
22 private static final long serialVersionUID = 1620492035834167297L;
23
24
25 private static final String ALL_OPERATIONS = "#all";
26
27
28 private List<String> operationPriority = new LinkedList<String>();
29
30
31 private Map<String, String> dataLevelPriority = new HashMap<String, String>();
32
33
34 private String defaultDataLevel;
35
36
37
38
39
40 public Priority(String defaultDataLevel) {
41 this.defaultDataLevel = defaultDataLevel;
42 }
43
44
45
46
47
48
49
50 public void addOperationPriority(String actionClass, String operationCode) {
51 String allOperations = actionClass + "." +ALL_OPERATIONS;
52 if(operationPriority.contains(allOperations)){
53 operationPriority.remove(allOperations);
54 }
55 operationPriority.add(actionClass + "." + operationCode);
56 }
57
58
59
60
61
62
63
64 public void addAllOperationPriorityOf(String actionClass) {
65 operationPriority.add(actionClass + "." + ALL_OPERATIONS);
66 }
67
68
69
70
71
72 public void removeAllOperationProrityOf(String actionClass) {
73 operationPriority.add(actionClass + "." + ALL_OPERATIONS);
74 }
75
76
77
78
79
80
81
82 public void addDataPriority(String actionClass, String dataLevelCode) {
83 dataLevelPriority.put(actionClass, dataLevelCode);
84 }
85
86
87
88
89
90
91
92 public boolean havePriority(Resource res) {
93 if (operationPriority.contains(res.getActionClass() + "." + res.getOperationCode())) {
94 return true;
95 } else {
96 return operationPriority.contains(res.getActionClass() + "." + ALL_OPERATIONS);
97 }
98 }
99
100
101
102
103
104 public String getDataLevelCode(String resourceCode) {
105 if (dataLevelPriority.containsKey(resourceCode)) {
106 return dataLevelPriority.get(resourceCode);
107 }
108 return defaultDataLevel;
109 }
110
111 public String getDefaultDataLevel() {
112 return defaultDataLevel;
113 }
114
115
116
117
118
119
120 public Set<String> getPriorityActionNames() {
121 Set<String> actions = new HashSet<String>();
122 for (String priority : operationPriority) {
123 actions.add(priority.substring(0, priority.lastIndexOf('.')));
124 }
125 return actions;
126 }
127
128 public List<String> getOperationPriorities(){
129 return this.operationPriority;
130 }
131
132 public Map<String,String> getDataLevelPriorities(){
133 return this.dataLevelPriority;
134 }
135
136 public void appendPriority(Priority priority){
137 operationPriority.addAll(priority.getOperationPriorities());
138
139 dataLevelPriority.putAll(priority.getDataLevelPriorities());
140 }
141 }