View Javadoc

1   /*
2    * Created on Aug 31, 2004
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      /* (non-Javadoc)
25       * @see net.sourceforge.barbecue.Barcode#calculateChecksum()
26       */
27      protected Module calculateChecksum() {
28          return null;
29      }
30  
31      /* (non-Javadoc)
32       * @see net.sourceforge.barbecue.Barcode#encodeData()
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          //add the check digit
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      /* (non-Javadoc)
55       * @see net.sourceforge.barbecue.Barcode#getBarcodeWidth(int)
56       */
57      protected double getBarcodeWidth(int resolution) {
58          return 0;
59      }
60  
61      /* (non-Javadoc)
62       * @see net.sourceforge.barbecue.Barcode#getPostAmble()
63       */
64      protected Module getPostAmble() {
65          return ModuleFactory.START_STOP;
66      }
67  
68      /* (non-Javadoc)
69       * @see net.sourceforge.barbecue.Barcode#getPreAmble()
70       */
71      protected Module getPreAmble() {
72          return ModuleFactory.START_STOP;
73      }
74  
75      /* (non-Javadoc)
76       * @see java.awt.Component#getHeight()
77       */
78      public int getHeight() {
79          return HEIGHT;
80      }
81  
82  }