1 package com.github.mygreen.cellformatter;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Locale;
6 import java.util.concurrent.CopyOnWriteArrayList;
7
8 import com.github.mygreen.cellformatter.callback.Callback;
9 import com.github.mygreen.cellformatter.lang.MSColor;
10 import com.github.mygreen.cellformatter.lang.MSLocale;
11
12
13
14
15
16
17
18
19
20
21 public abstract class ConditionFormatter {
22
23
24 protected final String pattern;
25
26
27 protected ConditionOperator operator;
28
29
30 protected MSLocale locale;
31
32
33 protected MSColor color;
34
35
36 protected List<String> conditions = new CopyOnWriteArrayList<>();
37
38
39 protected List<Callback<?>> callbacks = new CopyOnWriteArrayList<>();
40
41 public ConditionFormatter(final String pattern) {
42 this.pattern = pattern;
43 }
44
45
46
47
48
49 public abstract FormatterType getType();
50
51
52
53
54
55
56
57 public abstract boolean isMatch(CommonCell cell);
58
59
60
61
62
63
64 public CellFormatResult format(CommonCell cell) {
65 return format(cell, Locale.getDefault());
66 }
67
68
69
70
71
72
73
74 public abstract CellFormatResult format(CommonCell cell, Locale runtimeLocale);
75
76
77
78
79
80 public boolean isDateFormatter() {
81 return getType() == FormatterType.Date;
82 }
83
84
85
86
87
88 public boolean isNumberFormatter() {
89 return getType() == FormatterType.Number;
90 }
91
92
93
94
95
96 public boolean isTextFormatter() {
97 return getType() == FormatterType.Text;
98 }
99
100
101
102
103
104 public String getPattern() {
105 return pattern;
106 }
107
108
109
110
111
112 public void addCondition(final String condition) {
113 this.conditions.add(condition);
114 }
115
116
117
118
119
120 public void addAllCondition(final List<String> conditions) {
121 this.conditions.addAll(conditions);
122 }
123
124
125
126
127
128 public List<String> getConditions() {
129 return conditions;
130 }
131
132
133
134
135
136 public MSColor getColor() {
137 return color;
138 }
139
140
141
142
143 public void setColor(MSColor color) {
144 this.color = color;
145 }
146
147
148
149
150
151 public ConditionOperator getOperator() {
152 return operator;
153 }
154
155
156
157
158
159 public void setOperator(ConditionOperator operator) {
160 this.operator = operator;
161 }
162
163
164
165
166
167 public MSLocale getLocale() {
168 return locale;
169 }
170
171
172
173
174
175 public void setLocale(MSLocale locale) {
176 this.locale = locale;
177 }
178
179
180
181
182
183 public void addCallback(final Callback<?> callback) {
184 this.callbacks.add(callback);
185 }
186
187
188
189
190 public void addFirstCallcack(final Callback<?> callback) {
191
192 List<Callback<?>> list = new ArrayList<Callback<?>>();
193 list.add(callback);
194 list.addAll(callbacks);
195
196
197 callbacks.clear();
198 callbacks.addAll(list);
199 }
200
201
202
203
204
205 public List<Callback<?>> getCallbacks() {
206 return callbacks;
207 }
208 }