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.codabar;
28
29 import net.sourceforge.barbecue.Module;
30
31 import java.util.Map;
32 import java.util.HashMap;
33
34 /**
35 * Codabar barcode module definitions.
36 *
37 * @author <a href="mailto:opensource@ianbourke.com">Ian Bourke</a>
38 */
39 final class ModuleFactory {
40 private static final Map SET = new HashMap();
41
42 static {
43 init();
44 }
45
46
47 /**
48 * No public access.
49 */
50 private ModuleFactory() {
51 }
52
53
54 /**
55 * Initialise the module definitions.
56 */
57 private static void init() {
58 SET.put("0", new Module(new int[] {1, 1, 1, 1, 1, 2, 2}));
59 SET.put("1", new Module(new int[] {1, 1, 1, 1, 2, 2, 1}));
60 SET.put("2", new Module(new int[] {1, 1, 1, 2, 1, 1, 2}));
61 SET.put("3", new Module(new int[] {2, 2, 1, 1, 1, 1, 1}));
62 SET.put("4", new Module(new int[] {1, 1, 2, 1, 1, 2, 1}));
63 SET.put("5", new Module(new int[] {2, 1, 1, 1, 1, 2, 1}));
64 SET.put("6", new Module(new int[] {1, 2, 1, 1, 1, 1, 2}));
65 SET.put("7", new Module(new int[] {1, 2, 1, 1, 2, 1, 1}));
66 SET.put("8", new Module(new int[] {1, 2, 2, 1, 1, 1, 1}));
67 SET.put("9", new Module(new int[] {2, 1, 1, 2, 1, 1, 1}));
68 SET.put("-", new Module(new int[] {1, 1, 1, 2, 2, 1, 1}));
69 SET.put("$", new Module(new int[] {1, 1, 2, 2, 1, 1, 1}));
70 SET.put(":", new Module(new int[] {2, 1, 1, 1, 2, 1, 2}));
71 SET.put("/", new Module(new int[] {2, 1, 2, 1, 1, 1, 2}));
72 SET.put(".", new Module(new int[] {2, 1, 2, 1, 2, 1, 1}));
73 SET.put("+", new Module(new int[] {1, 1, 2, 2, 2, 2, 2}));
74 SET.put("A", new Module(new int[] {1, 1, 2, 2, 1, 2, 1}));
75 SET.put("B", new Module(new int[] {1, 1, 1, 2, 1, 2, 2}));
76 SET.put("C", new Module(new int[] {1, 2, 1, 2, 1, 1, 2}));
77 SET.put("D", new Module(new int[] {1, 1, 1, 2, 2, 2, 1}));
78 }
79
80 /**
81 * Returns the module that represents the specified character.
82 * @param key The data character to get the encoding module for
83 * @return The module that encodes the given char
84 */
85 public static Module getModule(String key) {
86 Module module = null;
87 module = (Module) SET.get(key);
88 module.setSymbol(key);
89 return module;
90 }
91
92 /**
93 * Indicates whether the given character is valid for this barcode or not.
94 * This basically just checks to see whether the key is in the list of
95 * encoded characters.
96 * @param key The key to check for validity
97 * @return True if the key is valid, false otherwise
98 */
99 public static boolean isValid(String key) {
100 return SET.containsKey(key);
101 }
102 }