View Javadoc

1   /***********************************************************************************************************************
2    * Copyright (c) 2004, 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.twoOfFive;
28  
29  import net.sourceforge.barbecue.Module;
30  
31  import java.util.Map;
32  import java.util.HashMap;
33  
34  /**
35   * Interleave 2 of 5 barcode module definitions.
36   *
37   * @author <a href="mailto:james@metalskin.com">James Jenner</a>
38   */
39  final class Int2of5ModuleFactory extends Std2of5ModuleFactory {
40      public static final Module START_CHAR = new Module(new int[] {1, 1, 1, 1});
41      public static final Module END_CHAR = new Module(new int[] {3, 1, 1});
42      
43      /**
44       * No public access.
45       */
46      protected Int2of5ModuleFactory() {
47      }
48      
49      /**
50       * Returns the module that represents the specified characters.
51       * Interleave uses one character for the bars and the other for
52       * the spaces, so for each 'module' two characters are required 
53       * to determine the resulting module.
54       * @param barValue  The data character for the bars
55       * @param spaceValue The data character for the spaces
56       * @return The module that encodes the given characters
57       */
58      public static Module getModule(String barValue, String spaceValue) {
59          Module module = null;
60          int[] bar = null;
61          int[] space = null;
62          bar = (int[])SET.get(barValue);
63          space = (int[])SET.get(spaceValue);
64          
65          // this should always be true, but best to check just in case...
66          if(bar != null && bar.length == 5 && space != null && space.length == 5) {
67              
68              // create the new module based on the selected bar val and space val
69              module = new Module(new int[] {
70                  bar[0], space[0], 
71                  bar[1], space[1], 
72                  bar[2], space[2], 
73                  bar[3], space[3], 
74                  bar[4], space[4]
75              });
76              module.setSymbol(barValue + spaceValue);
77          }
78          
79          return module;
80      }
81  }