1 /***********************************************************************************************************************
2 * Copyright (c) 2003, International Barcode Consortium
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this list of
11 * conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 * Neither the name of the International Barcode Consortium nor the names of any contributors may be used to endorse
14 * or promote products derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 ***********************************************************************************************************************/
26
27 package net.sourceforge.barbecue.linear.code128;
28
29 import net.sourceforge.barbecue.Module;
30
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 /**
37 * Code 128 barcode module definitions.
38 *
39 * @author <a href="mailto:opensource@ianbourke.com">Ian Bourke</a>
40 */
41 public final class ModuleFactory {
42 private static final List A_KEYS = new ArrayList();
43 private static final List B_KEYS = new ArrayList();
44 private static final List C_KEYS = new ArrayList();
45 private static final Map A_SET = new HashMap();
46 private static final Map B_SET = new HashMap();
47 private static final Map C_SET = new HashMap();
48
49 static {
50 initA();
51 initB();
52 initC();
53 }
54
55
56 /**
57 * Cannot construct.
58 */
59 private ModuleFactory() {
60 }
61
62
63 /**
64 * Initialise the module definitions.
65 */
66 private static void initA() {
67 A_KEYS.add(" "); A_SET.put(" ", new Module(new int[] {2, 1, 2, 2, 2, 2}));
68 A_KEYS.add("!"); A_SET.put("!", new Module(new int[] {2, 2, 2, 1, 2, 2}));
69 A_KEYS.add("\""); A_SET.put("\"", new Module(new int[] {2, 2, 2, 2, 2, 1}));
70 A_KEYS.add("#"); A_SET.put("#", new Module(new int[] {1, 2, 1, 2, 2, 3}));
71 A_KEYS.add("$"); A_SET.put("$", new Module(new int[] {1, 2, 1, 3, 2, 2}));
72 A_KEYS.add("%"); A_SET.put("%", new Module(new int[] {1, 3, 1, 2, 2, 2}));
73 A_KEYS.add("&"); A_SET.put("&", new Module(new int[] {1, 2, 2, 2, 1, 3}));
74 A_KEYS.add("'"); A_SET.put("'", new Module(new int[] {1, 2, 2, 3, 1, 2}));
75 A_KEYS.add("("); A_SET.put("(", new Module(new int[] {1, 3, 2, 2, 1, 2}));
76 A_KEYS.add(")"); A_SET.put(")", new Module(new int[] {2, 2, 1, 2, 1, 3}));
77 A_KEYS.add("*"); A_SET.put("*", new Module(new int[] {2, 2, 1, 3, 1, 2}));
78 A_KEYS.add("+"); A_SET.put("+", new Module(new int[] {2, 3, 1, 2, 1, 2}));
79 A_KEYS.add(","); A_SET.put(",", new Module(new int[] {1, 1, 2, 2, 3, 2}));
80 A_KEYS.add("-"); A_SET.put("-", new Module(new int[] {1, 2, 2, 1, 3, 2}));
81 A_KEYS.add("."); A_SET.put(".", new Module(new int[] {1, 2, 2, 2, 3, 1}));
82 A_KEYS.add("/"); A_SET.put("/", new Module(new int[] {1, 1, 3, 2, 2, 2}));
83 A_KEYS.add("0"); A_SET.put("0", new Module(new int[] {1, 2, 3, 1, 2, 2}));
84 A_KEYS.add("1"); A_SET.put("1", new Module(new int[] {1, 2, 3, 2, 2, 1}));
85 A_KEYS.add("2"); A_SET.put("2", new Module(new int[] {2, 2, 3, 2, 1, 1}));
86 A_KEYS.add("3"); A_SET.put("3", new Module(new int[] {2, 2, 1, 1, 3, 2}));
87 A_KEYS.add("4"); A_SET.put("4", new Module(new int[] {2, 2, 1, 2, 3, 1}));
88 A_KEYS.add("5"); A_SET.put("5", new Module(new int[] {2, 1, 3, 2, 1, 2}));
89 A_KEYS.add("6"); A_SET.put("6", new Module(new int[] {2, 2, 3, 1, 1, 2}));
90 A_KEYS.add("7"); A_SET.put("7", new Module(new int[] {3, 1, 2, 1, 3, 1}));
91 A_KEYS.add("8"); A_SET.put("8", new Module(new int[] {3, 1, 1, 2, 2, 2}));
92 A_KEYS.add("9"); A_SET.put("9", new Module(new int[] {3, 2, 1, 1, 2, 2}));
93 A_KEYS.add(":"); A_SET.put(":", new Module(new int[] {3, 2, 1, 2, 2, 1}));
94 A_KEYS.add(";"); A_SET.put(";", new Module(new int[] {3, 1, 2, 2, 1, 2}));
95 A_KEYS.add("<"); A_SET.put("<", new Module(new int[] {3, 2, 2, 1, 1, 2}));
96 A_KEYS.add("="); A_SET.put("=", new Module(new int[] {3, 2, 2, 2, 1, 1}));
97 A_KEYS.add(">"); A_SET.put(">", new Module(new int[] {2, 1, 2, 1, 2, 3}));
98 A_KEYS.add("?"); A_SET.put("?", new Module(new int[] {2, 1, 2, 3, 2, 1}));
99 A_KEYS.add("@"); A_SET.put("@", new Module(new int[] {2, 3, 2, 1, 2, 1}));
100 A_KEYS.add("A"); A_SET.put("A", new Module(new int[] {1, 1, 1, 3, 2, 3}));
101 A_KEYS.add("B"); A_SET.put("B", new Module(new int[] {1, 3, 1, 1, 2, 3}));
102 A_KEYS.add("C"); A_SET.put("C", new Module(new int[] {1, 3, 1, 3, 2, 1}));
103 A_KEYS.add("D"); A_SET.put("D", new Module(new int[] {1, 1, 2, 3, 1, 3}));
104 A_KEYS.add("E"); A_SET.put("E", new Module(new int[] {1, 3, 2, 1, 1, 3}));
105 A_KEYS.add("F"); A_SET.put("F", new Module(new int[] {1, 3, 2, 3, 1, 1}));
106 A_KEYS.add("G"); A_SET.put("G", new Module(new int[] {2, 1, 1, 3, 1, 3}));
107 A_KEYS.add("H"); A_SET.put("H", new Module(new int[] {2, 3, 1, 1, 1, 3}));
108 A_KEYS.add("I"); A_SET.put("I", new Module(new int[] {2, 3, 1, 3, 1, 1}));
109 A_KEYS.add("J"); A_SET.put("J", new Module(new int[] {1, 1, 2, 1, 3, 3}));
110 A_KEYS.add("K"); A_SET.put("K", new Module(new int[] {1, 1, 2, 3, 3, 1}));
111 A_KEYS.add("L"); A_SET.put("L", new Module(new int[] {1, 3, 2, 1, 3, 1}));
112 A_KEYS.add("M"); A_SET.put("M", new Module(new int[] {1, 1, 3, 1, 2, 3}));
113 A_KEYS.add("N"); A_SET.put("N", new Module(new int[] {1, 1, 3, 3, 2, 1}));
114 A_KEYS.add("O"); A_SET.put("O", new Module(new int[] {1, 3, 3, 1, 2, 1}));
115 A_KEYS.add("P"); A_SET.put("P", new Module(new int[] {3, 1, 3, 1, 2, 1}));
116 A_KEYS.add("Q"); A_SET.put("Q", new Module(new int[] {2, 1, 1, 3, 3, 1}));
117 A_KEYS.add("R"); A_SET.put("R", new Module(new int[] {2, 3, 1, 1, 3, 1}));
118 A_KEYS.add("S"); A_SET.put("S", new Module(new int[] {2, 1, 3, 1, 1, 3}));
119 A_KEYS.add("T"); A_SET.put("T", new Module(new int[] {2, 1, 3, 3, 1, 1}));
120 A_KEYS.add("U"); A_SET.put("U", new Module(new int[] {2, 1, 3, 1, 3, 1}));
121 A_KEYS.add("V"); A_SET.put("V", new Module(new int[] {3, 1, 1, 1, 2, 3}));
122 A_KEYS.add("W"); A_SET.put("W", new Module(new int[] {3, 1, 1, 3, 2, 1}));
123 A_KEYS.add("X"); A_SET.put("X", new Module(new int[] {3, 3, 1, 1, 2, 1}));
124 A_KEYS.add("Y"); A_SET.put("Y", new Module(new int[] {3, 1, 2, 1, 1, 3}));
125 A_KEYS.add("Z"); A_SET.put("Z", new Module(new int[] {3, 1, 2, 3, 1, 1}));
126 A_KEYS.add("["); A_SET.put("[", new Module(new int[] {3, 3, 2, 1, 1, 1}));
127 A_KEYS.add("\\"); A_SET.put("\\", new Module(new int[] {3, 1, 4, 1, 1, 1}));
128 A_KEYS.add("]"); A_SET.put("]", new Module(new int[] {2, 2, 1, 4, 1, 1}));
129 A_KEYS.add("^"); A_SET.put("^", new Module(new int[] {4, 3, 1, 1, 1, 1}));
130 A_KEYS.add("_"); A_SET.put("_", new Module(new int[] {1, 1, 1, 2, 2, 4}));
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 A_KEYS.add("\304"); A_SET.put("\304", new Module(new int[] {1, 1, 4, 3, 1, 1}));
164 A_KEYS.add("\305"); A_SET.put("\305", new Module(new int[] {4, 1, 1, 1, 1, 3}));
165 A_KEYS.add("\306"); A_SET.put("\306", new ShiftModule(new int[] {4, 1, 1, 3, 1, 1}));
166 A_KEYS.add("\307");
167 A_SET.put("\307", new CodeChangeModule(new int[] {1, 1, 3, 1, 4, 1}, Code128Barcode.C));
168 A_KEYS.add("\310");
169 A_SET.put("\310", new CodeChangeModule(new int[] {1, 1, 4, 1, 3, 1}, Code128Barcode.B));
170 A_KEYS.add("\311");
171 A_SET.put("\311", new Module(new int[] {3, 1, 1, 1, 4, 1}));
172 A_KEYS.add("\312");
173 A_SET.put("\312", new Module(new int[] {4, 1, 1, 1, 3, 1}));
174 }
175
176 /**
177 * Initialise the module definitions.
178 */
179 private static void initB() {
180 B_KEYS.add(" "); B_SET.put(" ", new Module(new int[] {2, 1, 2, 2, 2, 2}));
181 B_KEYS.add("!"); B_SET.put("!", new Module(new int[] {2, 2, 2, 1, 2, 2}));
182 B_KEYS.add("\""); B_SET.put("\"", new Module(new int[] {2, 2, 2, 2, 2, 1}));
183 B_KEYS.add("#"); B_SET.put("#", new Module(new int[] {1, 2, 1, 2, 2, 3}));
184 B_KEYS.add("$"); B_SET.put("$", new Module(new int[] {1, 2, 1, 3, 2, 2}));
185 B_KEYS.add("%"); B_SET.put("%", new Module(new int[] {1, 3, 1, 2, 2, 2}));
186 B_KEYS.add("&"); B_SET.put("&", new Module(new int[] {1, 2, 2, 2, 1, 3}));
187 B_KEYS.add("'"); B_SET.put("'", new Module(new int[] {1, 2, 2, 3, 1, 2}));
188 B_KEYS.add("("); B_SET.put("(", new Module(new int[] {1, 3, 2, 2, 1, 2}));
189 B_KEYS.add(")"); B_SET.put(")", new Module(new int[] {2, 2, 1, 2, 1, 3}));
190 B_KEYS.add("*"); B_SET.put("*", new Module(new int[] {2, 2, 1, 3, 1, 2}));
191 B_KEYS.add("+"); B_SET.put("+", new Module(new int[] {2, 3, 1, 2, 1, 2}));
192 B_KEYS.add(","); B_SET.put(",", new Module(new int[] {1, 1, 2, 2, 3, 2}));
193 B_KEYS.add("-"); B_SET.put("-", new Module(new int[] {1, 2, 2, 1, 3, 2}));
194 B_KEYS.add("."); B_SET.put(".", new Module(new int[] {1, 2, 2, 2, 3, 1}));
195 B_KEYS.add("/"); B_SET.put("/", new Module(new int[] {1, 1, 3, 2, 2, 2}));
196 B_KEYS.add("0"); B_SET.put("0", new Module(new int[] {1, 2, 3, 1, 2, 2}));
197 B_KEYS.add("1"); B_SET.put("1", new Module(new int[] {1, 2, 3, 2, 2, 1}));
198 B_KEYS.add("2"); B_SET.put("2", new Module(new int[] {2, 2, 3, 2, 1, 1}));
199 B_KEYS.add("3"); B_SET.put("3", new Module(new int[] {2, 2, 1, 1, 3, 2}));
200 B_KEYS.add("4"); B_SET.put("4", new Module(new int[] {2, 2, 1, 2, 3, 1}));
201 B_KEYS.add("5"); B_SET.put("5", new Module(new int[] {2, 1, 3, 2, 1, 2}));
202 B_KEYS.add("6"); B_SET.put("6", new Module(new int[] {2, 2, 3, 1, 1, 2}));
203 B_KEYS.add("7"); B_SET.put("7", new Module(new int[] {3, 1, 2, 1, 3, 1}));
204 B_KEYS.add("8"); B_SET.put("8", new Module(new int[] {3, 1, 1, 2, 2, 2}));
205 B_KEYS.add("9"); B_SET.put("9", new Module(new int[] {3, 2, 1, 1, 2, 2}));
206 B_KEYS.add(":"); B_SET.put(":", new Module(new int[] {3, 2, 1, 2, 2, 1}));
207 B_KEYS.add(";"); B_SET.put(";", new Module(new int[] {3, 1, 2, 2, 1, 2}));
208 B_KEYS.add("<"); B_SET.put("<", new Module(new int[] {3, 2, 2, 1, 1, 2}));
209 B_KEYS.add("="); B_SET.put("=", new Module(new int[] {3, 2, 2, 2, 1, 1}));
210 B_KEYS.add(">"); B_SET.put(">", new Module(new int[] {2, 1, 2, 1, 2, 3}));
211 B_KEYS.add("?"); B_SET.put("?", new Module(new int[] {2, 1, 2, 3, 2, 1}));
212 B_KEYS.add("@"); B_SET.put("@", new Module(new int[] {2, 3, 2, 1, 2, 1}));
213 B_KEYS.add("A"); B_SET.put("A", new Module(new int[] {1, 1, 1, 3, 2, 3}));
214 B_KEYS.add("B"); B_SET.put("B", new Module(new int[] {1, 3, 1, 1, 2, 3}));
215 B_KEYS.add("C"); B_SET.put("C", new Module(new int[] {1, 3, 1, 3, 2, 1}));
216 B_KEYS.add("D"); B_SET.put("D", new Module(new int[] {1, 1, 2, 3, 1, 3}));
217 B_KEYS.add("E"); B_SET.put("E", new Module(new int[] {1, 3, 2, 1, 1, 3}));
218 B_KEYS.add("F"); B_SET.put("F", new Module(new int[] {1, 3, 2, 3, 1, 1}));
219 B_KEYS.add("G"); B_SET.put("G", new Module(new int[] {2, 1, 1, 3, 1, 3}));
220 B_KEYS.add("H"); B_SET.put("H", new Module(new int[] {2, 3, 1, 1, 1, 3}));
221 B_KEYS.add("I"); B_SET.put("I", new Module(new int[] {2, 3, 1, 3, 1, 1}));
222 B_KEYS.add("J"); B_SET.put("J", new Module(new int[] {1, 1, 2, 1, 3, 3}));
223 B_KEYS.add("K"); B_SET.put("K", new Module(new int[] {1, 1, 2, 3, 3, 1}));
224 B_KEYS.add("L"); B_SET.put("L", new Module(new int[] {1, 3, 2, 1, 3, 1}));
225 B_KEYS.add("M"); B_SET.put("M", new Module(new int[] {1, 1, 3, 1, 2, 3}));
226 B_KEYS.add("N"); B_SET.put("N", new Module(new int[] {1, 1, 3, 3, 2, 1}));
227 B_KEYS.add("O"); B_SET.put("O", new Module(new int[] {1, 3, 3, 1, 2, 1}));
228 B_KEYS.add("P"); B_SET.put("P", new Module(new int[] {3, 1, 3, 1, 2, 1}));
229 B_KEYS.add("Q"); B_SET.put("Q", new Module(new int[] {2, 1, 1, 3, 3, 1}));
230 B_KEYS.add("R"); B_SET.put("R", new Module(new int[] {2, 3, 1, 1, 3, 1}));
231 B_KEYS.add("S"); B_SET.put("S", new Module(new int[] {2, 1, 3, 1, 1, 3}));
232 B_KEYS.add("T"); B_SET.put("T", new Module(new int[] {2, 1, 3, 3, 1, 1}));
233 B_KEYS.add("U"); B_SET.put("U", new Module(new int[] {2, 1, 3, 1, 3, 1}));
234 B_KEYS.add("V"); B_SET.put("V", new Module(new int[] {3, 1, 1, 1, 2, 3}));
235 B_KEYS.add("W"); B_SET.put("W", new Module(new int[] {3, 1, 1, 3, 2, 1}));
236 B_KEYS.add("X"); B_SET.put("X", new Module(new int[] {3, 3, 1, 1, 2, 1}));
237 B_KEYS.add("Y"); B_SET.put("Y", new Module(new int[] {3, 1, 2, 1, 1, 3}));
238 B_KEYS.add("Z"); B_SET.put("Z", new Module(new int[] {3, 1, 2, 3, 1, 1}));
239 B_KEYS.add("["); B_SET.put("[", new Module(new int[] {3, 3, 2, 1, 1, 1}));
240 B_KEYS.add("\\"); B_SET.put("\\", new Module(new int[] {3, 1, 4, 1, 1, 1}));
241 B_KEYS.add("]"); B_SET.put("]", new Module(new int[] {2, 2, 1, 4, 1, 1}));
242 B_KEYS.add("^"); B_SET.put("^", new Module(new int[] {4, 3, 1, 1, 1, 1}));
243 B_KEYS.add("_"); B_SET.put("_", new Module(new int[] {1, 1, 1, 2, 2, 4}));
244 B_KEYS.add("`"); B_SET.put("`", new Module(new int[] {1, 1, 1, 4, 2, 2}));
245 B_KEYS.add("a"); B_SET.put("a", new Module(new int[] {1, 2, 1, 1, 2, 4}));
246 B_KEYS.add("b"); B_SET.put("b", new Module(new int[] {1, 2, 1, 4, 2, 1}));
247 B_KEYS.add("c"); B_SET.put("c", new Module(new int[] {1, 4, 1, 1, 2, 2}));
248 B_KEYS.add("d"); B_SET.put("d", new Module(new int[] {1, 4, 1, 2, 2, 1}));
249 B_KEYS.add("e"); B_SET.put("e", new Module(new int[] {1, 1, 2, 2, 1, 4}));
250 B_KEYS.add("f"); B_SET.put("f", new Module(new int[] {1, 1, 2, 4, 1, 2}));
251 B_KEYS.add("g"); B_SET.put("g", new Module(new int[] {1, 2, 2, 1, 1, 4}));
252 B_KEYS.add("h"); B_SET.put("h", new Module(new int[] {1, 2, 2, 4, 1, 1}));
253 B_KEYS.add("i"); B_SET.put("i", new Module(new int[] {1, 4, 2, 1, 1, 2}));
254 B_KEYS.add("j"); B_SET.put("j", new Module(new int[] {1, 4, 2, 2, 1, 1}));
255 B_KEYS.add("k"); B_SET.put("k", new Module(new int[] {2, 4, 1, 2, 1, 1}));
256 B_KEYS.add("l"); B_SET.put("l", new Module(new int[] {2, 2, 1, 1, 1, 4}));
257 B_KEYS.add("m"); B_SET.put("m", new Module(new int[] {4, 1, 3, 1, 1, 1}));
258 B_KEYS.add("n"); B_SET.put("n", new Module(new int[] {2, 4, 1, 1, 1, 2}));
259 B_KEYS.add("o"); B_SET.put("o", new Module(new int[] {1, 3, 4, 1, 1, 1}));
260 B_KEYS.add("p"); B_SET.put("p", new Module(new int[] {1, 1, 1, 2, 4, 2}));
261 B_KEYS.add("q"); B_SET.put("q", new Module(new int[] {1, 2, 1, 1, 4, 2}));
262 B_KEYS.add("r"); B_SET.put("r", new Module(new int[] {1, 2, 1, 2, 4, 1}));
263 B_KEYS.add("s"); B_SET.put("s", new Module(new int[] {1, 1, 4, 2, 1, 2}));
264 B_KEYS.add("t"); B_SET.put("t", new Module(new int[] {1, 2, 4, 1, 1, 2}));
265 B_KEYS.add("u"); B_SET.put("u", new Module(new int[] {1, 2, 4, 2, 1, 1}));
266 B_KEYS.add("v"); B_SET.put("v", new Module(new int[] {4, 1, 1, 2, 1, 2}));
267 B_KEYS.add("w"); B_SET.put("w", new Module(new int[] {4, 2, 1, 1, 1, 2}));
268 B_KEYS.add("x"); B_SET.put("x", new Module(new int[] {4, 2, 1, 2, 1, 1}));
269 B_KEYS.add("y"); B_SET.put("y", new Module(new int[] {2, 1, 2, 1, 4, 1}));
270 B_KEYS.add("z"); B_SET.put("z", new Module(new int[] {2, 1, 4, 1, 2, 1}));
271 B_KEYS.add("{"); B_SET.put("{", new Module(new int[] {4, 1, 2, 1, 2, 1}));
272 B_KEYS.add("|"); B_SET.put("|", new Module(new int[] {1, 1, 1, 1, 4, 3}));
273 B_KEYS.add("}"); B_SET.put("}", new Module(new int[] {1, 1, 1, 3, 4, 1}));
274 B_KEYS.add("~"); B_SET.put("~", new Module(new int[] {1, 3, 1, 1, 4, 1}));
275 B_KEYS.add("\303"); B_SET.put("\303", new Module(new int[] {1, 1, 4, 1, 1, 3}));
276 B_KEYS.add("\304"); B_SET.put("\304", new Module(new int[] {1, 1, 4, 3, 1, 1}));
277 B_KEYS.add("\305"); B_SET.put("\305", new Module(new int[] {4, 1, 1, 1, 1, 3}));
278 B_KEYS.add("\306");
279 B_SET.put("\306", new ShiftModule(new int[] {4, 1, 1, 3, 1, 1}));
280 B_KEYS.add("\307");
281 B_SET.put("\307", new CodeChangeModule(new int[] {1, 1, 3, 1, 4, 1}, Code128Barcode.C));
282 B_KEYS.add("\310");
283 B_SET.put("\310", new Module(new int[] {1, 1, 4, 1, 3, 1}));
284 B_KEYS.add("\311");
285 B_SET.put("\311", new CodeChangeModule(new int[] {3, 1, 1, 1, 4, 1}, Code128Barcode.A));
286 B_KEYS.add("\312");
287 B_SET.put("\312", new Module(new int[] {4, 1, 1, 1, 3, 1}));
288 }
289
290 /**
291 * Initialise the module definitions.
292 */
293 private static void initC() {
294 C_KEYS.add("00"); C_SET.put("00", new Module(new int[] {2, 1, 2, 2, 2, 2}));
295 C_KEYS.add("01"); C_SET.put("01", new Module(new int[] {2, 2, 2, 1, 2, 2}));
296 C_KEYS.add("02"); C_SET.put("02", new Module(new int[] {2, 2, 2, 2, 2, 1}));
297 C_KEYS.add("03"); C_SET.put("03", new Module(new int[] {1, 2, 1, 2, 2, 3}));
298 C_KEYS.add("04"); C_SET.put("04", new Module(new int[] {1, 2, 1, 3, 2, 2}));
299 C_KEYS.add("05"); C_SET.put("05", new Module(new int[] {1, 3, 1, 2, 2, 2}));
300 C_KEYS.add("06"); C_SET.put("06", new Module(new int[] {1, 2, 2, 2, 1, 3}));
301 C_KEYS.add("07"); C_SET.put("07", new Module(new int[] {1, 2, 2, 3, 1, 2}));
302 C_KEYS.add("08"); C_SET.put("08", new Module(new int[] {1, 3, 2, 2, 1, 2}));
303 C_KEYS.add("09"); C_SET.put("09", new Module(new int[] {2, 2, 1, 2, 1, 3}));
304 C_KEYS.add("10"); C_SET.put("10", new Module(new int[] {2, 2, 1, 3, 1, 2}));
305 C_KEYS.add("11"); C_SET.put("11", new Module(new int[] {2, 3, 1, 2, 1, 2}));
306 C_KEYS.add("12"); C_SET.put("12", new Module(new int[] {1, 1, 2, 2, 3, 2}));
307 C_KEYS.add("13"); C_SET.put("13", new Module(new int[] {1, 2, 2, 1, 3, 2}));
308 C_KEYS.add("14"); C_SET.put("14", new Module(new int[] {1, 2, 2, 2, 3, 1}));
309 C_KEYS.add("15"); C_SET.put("15", new Module(new int[] {1, 1, 3, 2, 2, 2}));
310 C_KEYS.add("16"); C_SET.put("16", new Module(new int[] {1, 2, 3, 1, 2, 2}));
311 C_KEYS.add("17"); C_SET.put("17", new Module(new int[] {1, 2, 3, 2, 2, 1}));
312 C_KEYS.add("18"); C_SET.put("18", new Module(new int[] {2, 2, 3, 2, 1, 1}));
313 C_KEYS.add("19"); C_SET.put("19", new Module(new int[] {2, 2, 1, 1, 3, 2}));
314 C_KEYS.add("20"); C_SET.put("20", new Module(new int[] {2, 2, 1, 2, 3, 1}));
315 C_KEYS.add("21"); C_SET.put("21", new Module(new int[] {2, 1, 3, 2, 1, 2}));
316 C_KEYS.add("22"); C_SET.put("22", new Module(new int[] {2, 2, 3, 1, 1, 2}));
317 C_KEYS.add("23"); C_SET.put("23", new Module(new int[] {3, 1, 2, 1, 3, 1}));
318 C_KEYS.add("24"); C_SET.put("24", new Module(new int[] {3, 1, 1, 2, 2, 2}));
319 C_KEYS.add("25"); C_SET.put("25", new Module(new int[] {3, 2, 1, 1, 2, 2}));
320 C_KEYS.add("26"); C_SET.put("26", new Module(new int[] {3, 2, 1, 2, 2, 1}));
321 C_KEYS.add("27"); C_SET.put("27", new Module(new int[] {3, 1, 2, 2, 1, 2}));
322 C_KEYS.add("28"); C_SET.put("28", new Module(new int[] {3, 2, 2, 1, 1, 2}));
323 C_KEYS.add("29"); C_SET.put("29", new Module(new int[] {3, 2, 2, 2, 1, 1}));
324 C_KEYS.add("30"); C_SET.put("30", new Module(new int[] {2, 1, 2, 1, 2, 3}));
325 C_KEYS.add("31"); C_SET.put("31", new Module(new int[] {2, 1, 2, 3, 2, 1}));
326 C_KEYS.add("32"); C_SET.put("32", new Module(new int[] {2, 3, 2, 1, 2, 1}));
327 C_KEYS.add("33"); C_SET.put("33", new Module(new int[] {1, 1, 1, 3, 2, 3}));
328 C_KEYS.add("34"); C_SET.put("34", new Module(new int[] {1, 3, 1, 1, 2, 3}));
329 C_KEYS.add("35"); C_SET.put("35", new Module(new int[] {1, 3, 1, 3, 2, 1}));
330 C_KEYS.add("36"); C_SET.put("36", new Module(new int[] {1, 1, 2, 3, 1, 3}));
331 C_KEYS.add("37"); C_SET.put("37", new Module(new int[] {1, 3, 2, 1, 1, 3}));
332 C_KEYS.add("38"); C_SET.put("38", new Module(new int[] {1, 3, 2, 3, 1, 1}));
333 C_KEYS.add("39"); C_SET.put("39", new Module(new int[] {2, 1, 1, 3, 1, 3}));
334 C_KEYS.add("40"); C_SET.put("40", new Module(new int[] {2, 3, 1, 1, 1, 3}));
335 C_KEYS.add("41"); C_SET.put("41", new Module(new int[] {2, 3, 1, 3, 1, 1}));
336 C_KEYS.add("42"); C_SET.put("42", new Module(new int[] {1, 1, 2, 1, 3, 3}));
337 C_KEYS.add("43"); C_SET.put("43", new Module(new int[] {1, 1, 2, 3, 3, 1}));
338 C_KEYS.add("44"); C_SET.put("44", new Module(new int[] {1, 3, 2, 1, 3, 1}));
339 C_KEYS.add("45"); C_SET.put("45", new Module(new int[] {1, 1, 3, 1, 2, 3}));
340 C_KEYS.add("46"); C_SET.put("46", new Module(new int[] {1, 1, 3, 3, 2, 1}));
341 C_KEYS.add("47"); C_SET.put("47", new Module(new int[] {1, 3, 3, 1, 2, 1}));
342 C_KEYS.add("48"); C_SET.put("48", new Module(new int[] {3, 1, 3, 1, 2, 1}));
343 C_KEYS.add("49"); C_SET.put("49", new Module(new int[] {2, 1, 1, 3, 3, 1}));
344 C_KEYS.add("50"); C_SET.put("50", new Module(new int[] {2, 3, 1, 1, 3, 1}));
345 C_KEYS.add("51"); C_SET.put("51", new Module(new int[] {2, 1, 3, 1, 1, 3}));
346 C_KEYS.add("52"); C_SET.put("52", new Module(new int[] {2, 1, 3, 3, 1, 1}));
347 C_KEYS.add("53"); C_SET.put("53", new Module(new int[] {2, 1, 3, 1, 3, 1}));
348 C_KEYS.add("54"); C_SET.put("54", new Module(new int[] {3, 1, 1, 1, 2, 3}));
349 C_KEYS.add("55"); C_SET.put("55", new Module(new int[] {3, 1, 1, 3, 2, 1}));
350 C_KEYS.add("56"); C_SET.put("56", new Module(new int[] {3, 3, 1, 1, 2, 1}));
351 C_KEYS.add("57"); C_SET.put("57", new Module(new int[] {3, 1, 2, 1, 1, 3}));
352 C_KEYS.add("58"); C_SET.put("58", new Module(new int[] {3, 1, 2, 3, 1, 1}));
353 C_KEYS.add("59"); C_SET.put("59", new Module(new int[] {3, 3, 2, 1, 1, 1}));
354 C_KEYS.add("60"); C_SET.put("60", new Module(new int[] {3, 1, 4, 1, 1, 1}));
355 C_KEYS.add("61"); C_SET.put("61", new Module(new int[] {2, 2, 1, 4, 1, 1}));
356 C_KEYS.add("62"); C_SET.put("62", new Module(new int[] {4, 3, 1, 1, 1, 1}));
357 C_KEYS.add("63"); C_SET.put("63", new Module(new int[] {1, 1, 1, 2, 2, 4}));
358 C_KEYS.add("64"); C_SET.put("64", new Module(new int[] {1, 1, 1, 4, 2, 2}));
359 C_KEYS.add("65"); C_SET.put("65", new Module(new int[] {1, 2, 1, 1, 2, 4}));
360 C_KEYS.add("66"); C_SET.put("66", new Module(new int[] {1, 2, 1, 4, 2, 1}));
361 C_KEYS.add("67"); C_SET.put("67", new Module(new int[] {1, 4, 1, 1, 2, 2}));
362 C_KEYS.add("68"); C_SET.put("68", new Module(new int[] {1, 4, 1, 2, 2, 1}));
363 C_KEYS.add("69"); C_SET.put("69", new Module(new int[] {1, 1, 2, 2, 1, 4}));
364 C_KEYS.add("70"); C_SET.put("70", new Module(new int[] {1, 1, 2, 4, 1, 2}));
365 C_KEYS.add("71"); C_SET.put("71", new Module(new int[] {1, 2, 2, 1, 1, 4}));
366 C_KEYS.add("72"); C_SET.put("72", new Module(new int[] {1, 2, 2, 4, 1, 1}));
367 C_KEYS.add("73"); C_SET.put("73", new Module(new int[] {1, 4, 2, 1, 1, 2}));
368 C_KEYS.add("74"); C_SET.put("74", new Module(new int[] {1, 4, 2, 2, 1, 1}));
369 C_KEYS.add("75"); C_SET.put("75", new Module(new int[] {2, 4, 1, 2, 1, 1}));
370 C_KEYS.add("76"); C_SET.put("76", new Module(new int[] {2, 2, 1, 1, 1, 4}));
371 C_KEYS.add("77"); C_SET.put("77", new Module(new int[] {4, 1, 3, 1, 1, 1}));
372 C_KEYS.add("78"); C_SET.put("78", new Module(new int[] {2, 4, 1, 1, 1, 2}));
373 C_KEYS.add("79"); C_SET.put("79", new Module(new int[] {1, 3, 4, 1, 1, 1}));
374 C_KEYS.add("80"); C_SET.put("80", new Module(new int[] {1, 1, 1, 2, 4, 2}));
375 C_KEYS.add("81"); C_SET.put("81", new Module(new int[] {1, 2, 1, 1, 4, 2}));
376 C_KEYS.add("82"); C_SET.put("82", new Module(new int[] {1, 2, 1, 2, 4, 1}));
377 C_KEYS.add("83"); C_SET.put("83", new Module(new int[] {1, 1, 4, 2, 1, 2}));
378 C_KEYS.add("84"); C_SET.put("84", new Module(new int[] {1, 2, 4, 1, 1, 2}));
379 C_KEYS.add("85"); C_SET.put("85", new Module(new int[] {1, 2, 4, 2, 1, 1}));
380 C_KEYS.add("86"); C_SET.put("86", new Module(new int[] {4, 1, 1, 2, 1, 2}));
381 C_KEYS.add("87"); C_SET.put("87", new Module(new int[] {4, 2, 1, 1, 1, 2}));
382 C_KEYS.add("88"); C_SET.put("88", new Module(new int[] {4, 2, 1, 2, 1, 1}));
383 C_KEYS.add("89"); C_SET.put("89", new Module(new int[] {2, 1, 2, 1, 4, 1}));
384 C_KEYS.add("90"); C_SET.put("90", new Module(new int[] {2, 1, 4, 1, 2, 1}));
385 C_KEYS.add("91"); C_SET.put("91", new Module(new int[] {4, 1, 2, 1, 2, 1}));
386 C_KEYS.add("92"); C_SET.put("92", new Module(new int[] {1, 1, 1, 1, 4, 3}));
387 C_KEYS.add("93"); C_SET.put("93", new Module(new int[] {1, 1, 1, 3, 4, 1}));
388 C_KEYS.add("94"); C_SET.put("94", new Module(new int[] {1, 3, 1, 1, 4, 1}));
389 C_KEYS.add("95"); C_SET.put("95", new Module(new int[] {1, 1, 4, 1, 1, 3}));
390 C_KEYS.add("96"); C_SET.put("96", new Module(new int[] {1, 1, 4, 3, 1, 1}));
391 C_KEYS.add("97"); C_SET.put("97", new Module(new int[] {4, 1, 1, 1, 1, 3}));
392 C_KEYS.add("98"); C_SET.put("98", new Module(new int[] {4, 1, 1, 3, 1, 1}));
393 C_KEYS.add("99"); C_SET.put("99", new Module(new int[] {1, 1, 3, 1, 4, 1}));
394 C_KEYS.add("\310");
395 C_SET.put("\310", new CodeChangeModule(new int[] {1, 1, 4, 1, 3, 1}, Code128Barcode.B));
396 C_KEYS.add("\311");
397 C_SET.put("\311", new CodeChangeModule(new int[] {3, 1, 1, 1, 4, 1}, Code128Barcode.A));
398 C_KEYS.add("\312");
399 C_SET.put("\312", new Module(new int[] {4, 1, 1, 1, 3, 1}));
400 }
401
402 /**
403 * Returns the module that represents the specified character and character set.
404 * @param key The data character to get the encoding module for
405 * @param mode The character set mode that is currently in use (A, B or C)
406 * @return The module that encodes the given char in the given character set
407 */
408 public static Module getModule(String key, int mode) {
409 Module module = null;
410 switch (mode) {
411 case Code128Barcode.A:
412 module = (Module) A_SET.get(key);
413 break;
414 case Code128Barcode.B:
415 module = (Module) B_SET.get(key);
416 break;
417 case Code128Barcode.C:
418 module = (Module) C_SET.get(key);
419 break;
420 }
421 if (module != null) {
422 module.setSymbol(key);
423 }
424 return module;
425 }
426
427 /**
428 * Returns the index of the given character in the encoding tables. This is used
429 * when calculating the checksum.
430 * @param key The data character sequence to get the index for
431 * @param mode The character set mode that is currently in use (A, B or C)
432 * @return The index for the given key
433 */
434 public static int getIndex(String key, int mode) {
435 List keys = getKeys(mode);
436 return keys.indexOf(key);
437 }
438
439 /**
440 * Returns the encoded module at the given index position. This is used to
441 * get the encoded checksum character.
442 * @param index The index to get the module for
443 * @param mode The character set mode that is currently in use (A, B or C)
444 * @return The module at the specified index
445 */
446 public static Module getModuleForIndex(int index, int mode) {
447 List keys = getKeys(mode);
448 return getModule((String) keys.get(index), mode);
449 }
450
451 private static List getKeys(int mode) {
452 switch (mode) {
453 case Code128Barcode.A:
454 return A_KEYS;
455 case Code128Barcode.C:
456 return C_KEYS;
457 }
458 return B_KEYS;
459 }
460 }