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
28 public class Interleaved25 extends AbstractBarcodeStrategy implements java.io.Serializable {
29
30 private static CharacterCode[] codes = {
31 new CharacterCode('1', new byte[] {3,1,1,1,3}, 1),
32 new CharacterCode('2', new byte[] {1,3,1,1,3}, 2),
33 new CharacterCode('3', new byte[] {3,3,1,1,1}, 3),
34 new CharacterCode('4', new byte[] {1,1,3,1,3}, 4),
35 new CharacterCode('5', new byte[] {3,1,3,1,1}, 5),
36 new CharacterCode('6', new byte[] {1,3,3,1,1}, 6),
37 new CharacterCode('7', new byte[] {1,1,1,3,3}, 7),
38 new CharacterCode('8', new byte[] {3,1,1,3,1}, 8),
39 new CharacterCode('9', new byte[] {1,3,1,3,1}, 9),
40 new CharacterCode('0', new byte[] {1,1,3,3,1}, 0),
41 new CharacterCode('A', new byte[] {1,1,1,1}, -1),
42 new CharacterCode('B', new byte[] {3,1,1}, -1)
43 };
44
45
46
47
48 public int requiresChecksum() {
49
50 return OPTIONAL_CHECKSUM;
51 }
52
53
54
55
56
57
58 protected CharacterCode[] getCodes() {
59 return Interleaved25.codes;
60 }
61
62
63
64
65
66
67 protected String augmentWithChecksum(String text) throws BarcodeException {
68 int check1 = 0;
69 int check2 = 0;
70 CharacterCode cc;
71 for (int i = 0; i < text.length(); i++) {
72 char ch = text.charAt(i);
73 cc = getCharacterCode(ch);
74 if (cc == null) {
75 throw new BarcodeException("Invalid character in barcode");
76 }
77
78 if (cc.check > 0) {
79 if ((i + text.length()) % 2 == 0) {
80 check1 += cc.check;
81 } else {
82 check2 += cc.check;
83 }
84 }
85 }
86 check2 *= 3;
87 int checkDigit = (10 - ((check1 + check2) % 10)) % 10;
88 text = text + new Integer(checkDigit).toString();
89 return text;
90 }
91
92
93
94
95 protected String postprocess(String text) {
96 if (text.length() % 2 != 0) {
97
98 text = "0" + text;
99 }
100 return text;
101 }
102
103
104
105
106 protected String preprocess(String text) {
107 return text;
108 }
109
110
111
112
113 protected boolean isInterleaved() {
114 return true;
115 }
116
117
118
119
120 protected char getStartSentinel() {
121 return 'A';
122 }
123
124
125
126
127 protected char getStopSentinel() {
128 return 'B';
129 }
130
131
132
133
134 protected byte getMarginWidth() {
135 return 11;
136 }
137
138
139
140
141 protected String getBarcodeLabelText(String text) {
142 return text;
143 }
144
145 }