1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jbarcodebean.model;
20
21 import net.sourceforge.jbarcodebean.BarcodeException;
22
23
24
25
26
27 public class MSI extends AbstractBarcodeStrategy implements java.io.Serializable {
28
29 private static CharacterCode[] codes = {
30 new CharacterCode('1', new byte[] {1,2,1,2,1,2,2,1}, 1),
31 new CharacterCode('2', new byte[] {1,2,1,2,2,1,1,3}, 2),
32 new CharacterCode('3', new byte[] {1,2,1,2,2,1,2,1}, 3),
33 new CharacterCode('4', new byte[] {1,2,2,1,1,2,1,3}, 4),
34 new CharacterCode('5', new byte[] {1,2,2,1,1,2,2,1}, 5),
35 new CharacterCode('6', new byte[] {1,2,2,1,2,1,1,3}, 6),
36 new CharacterCode('7', new byte[] {1,2,2,1,2,1,2,1}, 7),
37 new CharacterCode('8', new byte[] {2,1,1,2,1,2,1,3}, 8),
38 new CharacterCode('9', new byte[] {2,1,1,2,1,2,2,1}, 9),
39 new CharacterCode('0', new byte[] {1,2,1,2,1,2,1,3}, 0),
40 new CharacterCode('A', new byte[] {2,1}, -1),
41 new CharacterCode('B', new byte[] {1,2,1}, -1)
42 };
43
44
45
46
47 public int requiresChecksum() {
48
49 return MANDATORY_CHECKSUM;
50 }
51
52
53
54
55
56
57 protected CharacterCode[] getCodes() {
58 return MSI.codes;
59 }
60
61
62
63
64
65
66 protected String augmentWithChecksum(String text) throws BarcodeException {
67 String newNum = "";
68 for (int i = text.length() - 1; i >= 0; i -= 2 ) {
69 newNum = text.charAt(i) + newNum;
70 }
71 int check1 = Integer.parseInt(newNum) * 2;
72 newNum = new Integer(check1).toString();
73 int check2 = 0;
74 for (int i = 0; i < newNum.length(); i++) {
75 check2 += Integer.parseInt(newNum.substring(i, i + 1));
76 }
77 for (int i = text.length() - 2; i >= 0; i -= 2 ) {
78 check2 += Integer.parseInt(text.substring(i, i + 1));
79 }
80 int checkDigit = (10 - ((check2) % 10)) % 10;
81 text = text + new Integer(checkDigit).toString();
82 return text;
83 }
84
85
86
87
88 protected String postprocess(String text) {
89 return text;
90 }
91
92
93
94
95 protected String preprocess(String text) {
96 return text;
97 }
98
99
100
101
102 protected boolean isInterleaved() {
103 return false;
104 }
105
106
107
108
109 protected char getStartSentinel() {
110 return 'A';
111 }
112
113
114
115
116 protected char getStopSentinel() {
117 return 'B';
118 }
119
120
121
122
123 protected byte getMarginWidth() {
124 return 11;
125 }
126
127
128
129
130 protected String getBarcodeLabelText(String text) {
131 return text;
132 }
133
134 }