1
2
3
4 package net.sourceforge.barbecue.linear.postnet;
5
6 import net.sourceforge.barbecue.BarcodeException;
7 import net.sourceforge.barbecue.Module;
8 import net.sourceforge.barbecue.linear.LinearBarcode;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 /**
14 * @author Brendon Anderson
15 */
16 public class PostNetBarcode extends LinearBarcode {
17
18 protected final static int HEIGHT = 20;
19
20 public PostNetBarcode(String zipcode) throws BarcodeException {
21 super(zipcode);
22 }
23
24
25
26
27 protected Module calculateChecksum() {
28 return null;
29 }
30
31
32
33
34 protected Module[] encodeData() {
35 long sum = 0;
36 List modules = new ArrayList();
37 for (int i = 0; i < data.length(); i++) {
38 String c = String.valueOf(data.charAt(i));
39 Module module = ModuleFactory.getModule(c);
40 sum += Long.parseLong(c);
41 modules.add(module);
42 }
43
44
45 long check = (10 - (sum % 10));
46 if (check == 10) {
47 check = 0;
48 }
49
50 modules.add(ModuleFactory.getModule(String.valueOf(check)));
51 return (Module[]) modules.toArray(new PostNetModule[0]);
52 }
53
54
55
56
57 protected double getBarcodeWidth(int resolution) {
58 return 0;
59 }
60
61
62
63
64 protected Module getPostAmble() {
65 return ModuleFactory.START_STOP;
66 }
67
68
69
70
71 protected Module getPreAmble() {
72 return ModuleFactory.START_STOP;
73 }
74
75
76
77
78 public int getHeight() {
79 return HEIGHT;
80 }
81
82 }