Miscellaneous changes from FindBugs analysis
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sat, 22 Aug 2009 15:16:36 +0000 (15:16 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sat, 22 Aug 2009 15:16:36 +0000 (15:16 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1038 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/common/CharacterSetECI.java
core/src/com/google/zxing/datamatrix/detector/Detector.java
core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java

index dbb9144..44f05c3 100644 (file)
@@ -67,13 +67,13 @@ public final class CharacterSetECI extends ECI {
 
   private static void addCharacterSet(int value, String encodingName) {
     CharacterSetECI eci = new CharacterSetECI(value, encodingName);
-    VALUE_TO_ECI.put(new Integer(value), eci);
+    VALUE_TO_ECI.put(Integer.valueOf(value), eci);
     NAME_TO_ECI.put(encodingName, eci);
   }
 
   private static void addCharacterSet(int value, String[] encodingNames) {
     CharacterSetECI eci = new CharacterSetECI(value, encodingNames[0]);
-    VALUE_TO_ECI.put(new Integer(value), eci);
+    VALUE_TO_ECI.put(Integer.valueOf(value), eci);
     for (int i = 0; i < encodingNames.length; i++) {
       NAME_TO_ECI.put(encodingNames[i], eci);
     }
@@ -92,7 +92,7 @@ public final class CharacterSetECI extends ECI {
     if (value < 0 || value >= 900) {
       throw new IllegalArgumentException("Bad ECI value: " + value);
     }
-    return (CharacterSetECI) VALUE_TO_ECI.get(new Integer(value));
+    return (CharacterSetECI) VALUE_TO_ECI.get(Integer.valueOf(value));
   }
 
   /**
index 8467b88..f140aff 100644 (file)
@@ -42,7 +42,7 @@ public final class Detector {
   // Trick to avoid creating new Integer objects below -- a sort of crude copy of
   // the Integer.valueOf(int) optimization added in Java 5, not in J2ME
   private static final Integer[] INTEGERS =
-      { new Integer(0), new Integer(1), new Integer(2), new Integer(3), new Integer(4) };
+      { Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4) };
 
   private final BitMatrix image;
   private final MonochromeRectangleDetector rectangleDetector;
index 79e8313..dc27a8b 100644 (file)
@@ -30,14 +30,14 @@ final class BitMatrixParser {
 \r
   private static final int MAX_ROW_DIFFERENCE = 6;\r
   private static final int MAX_ROWS = 90;\r
-  private static final int MAX_COLUMNS = 30;\r
+  //private static final int MAX_COLUMNS = 30;\r
   // Maximum Codewords (Data + Error)\r
   private static final int MAX_CW_CAPACITY = 929;\r
   private static final int MODULES_IN_SYMBOL = 17;\r
 \r
   private final BitMatrix bitMatrix;\r
   private int rows = 0;\r
-  private int columns = 0;\r
+  //private int columns = 0;\r
 \r
   private int leftColumnECData = 0;\r
   private int rightColumnECData = 0;\r
@@ -58,7 +58,7 @@ final class BitMatrixParser {
    *\r
    * @return an array of codewords.\r
    */\r
-  int[] readCodewords() throws ReaderException {\r
+  int[] readCodewords() {\r
     int width = bitMatrix.getDimension();\r
     // TODO should be a rectangular matrix\r
     int height = width;\r
@@ -113,8 +113,7 @@ final class BitMatrixParser {
       } else {\r
         if (rowInProgress) {\r
           // Process Row\r
-          next = processRow(rowCounters, rowNumber, rowHeight,\r
-              moduleWidth, codewords, next);\r
+          next = processRow(rowCounters, rowNumber, rowHeight, codewords, next);\r
           if (next == -1) {\r
             // Something is wrong, since we have exceeded\r
             // the maximum columns in the specification.\r
@@ -142,8 +141,7 @@ final class BitMatrixParser {
         // TODO Maybe return error code\r
         return null;\r
       }\r
-      next = processRow(rowCounters, rowNumber, rowHeight, moduleWidth,\r
-          codewords, next);\r
+      next = processRow(rowCounters, rowNumber, rowHeight, codewords, next);\r
       rowNumber++;\r
       rows = rowNumber;\r
     }\r
@@ -160,7 +158,7 @@ final class BitMatrixParser {
    */\r
   private static int[] trimArray(int[] array, int size) {\r
     if (size > 0) {\r
-      int a[] = new int[size];\r
+      int[] a = new int[size];\r
       for (int i = 0; i < size; i++) {\r
         a[i] = array[i];\r
       }\r
@@ -172,36 +170,31 @@ final class BitMatrixParser {
 \r
   /**\r
    * Convert the symbols in the row to codewords.\r
+   * Each PDF417 symbol character consists of four bar elements and four space\r
+   * elements, each of which can be one to six modules wide. The four bar and\r
+   * four space elements shall measure 17 modules in total.\r
    *\r
    * @param rowCounters an array containing the counts of black pixels for each column\r
    *                    in the row.\r
    * @param rowNumber   the current row number of codewords.\r
    * @param rowHeight   the height of this row in pixels.\r
-   * @param moduleWidth the size of a module in pixels.\r
    * @param codewords   the codeword array to save codewords into.\r
    * @param next        the next available index into the codewords array.\r
    * @return the next available index into the codeword array after processing\r
    *         this row.\r
-   * @throws ReaderException\r
    */\r
-  /*\r
-  * Each PDF417 symbol character consists of four bar elements and four space\r
-  * elements, each of which can be one to six modules wide. The four bar and\r
-  * four space elements shall measure 17 modules in total.\r
-  */\r
-  int processRow(int[] rowCounters, int rowNumber, int rowHeight,\r
-                 float moduleWidth, int[] codewords, int next) throws ReaderException {\r
+  int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next) {\r
     int width = bitMatrix.getDimension();\r
     int columnNumber = 0;\r
     long symbol = 0;\r
     for (int i = 0; i < width; i += MODULES_IN_SYMBOL) {\r
       for (int mask = MODULES_IN_SYMBOL - 1; mask >= 0; mask--) {\r
-        if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight / 2) {\r
+        if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight >>> 1) {\r
           symbol |= 1 << mask;\r
         }\r
       }\r
       if (columnNumber > 0) {\r
-        int cw = getCodeword(symbol, rowNumber);\r
+        int cw = getCodeword(symbol);\r
         // if (debug) System.out.println(" " + Long.toBinaryString(symbol) +\r
         // " cw=" +cw + " ColumnNumber=" +columnNumber + "i=" +i);\r
         if (cw < 0 && i < width - MODULES_IN_SYMBOL) {\r
@@ -214,7 +207,7 @@ final class BitMatrixParser {
         }\r
       } else {\r
         // Left row indicator column\r
-        int cw = getCodeword(symbol, rowNumber);\r
+        int cw = getCodeword(symbol);\r
         // if (debug) System.out.println(" " + Long.toBinaryString(symbol) +\r
         // " cw=" +cw + " ColumnNumber=" +columnNumber + "i=" +i);\r
         if (ecLevel < 0) {\r
@@ -230,12 +223,12 @@ final class BitMatrixParser {
         }\r
       }\r
       symbol = 0;\r
-      columns = columnNumber;\r
+      //columns = columnNumber;\r
       columnNumber++;\r
     }\r
     if (columnNumber > 1) {\r
       // Right row indicator column is in codeword[next]\r
-      columns--;\r
+      //columns--;\r
       // Overwrite the last codeword i.e. Right Row Indicator\r
       --next;\r
       if (ecLevel < 0) {\r
@@ -259,18 +252,16 @@ final class BitMatrixParser {
   }\r
 \r
   /**\r
-   * Build a symbol from the pixels\r
+   * Build a symbol from the pixels.\r
+   * Each symbol character is defined by an 8-digit bar-space sequence which\r
+   * represents the module widths of the eight elements of that symbol\r
+   * character.\r
    *\r
    * @param counters  array of pixel counter corresponding to each Bar/Space pattern.\r
-   * @param rowNumber\r
    * @return the symbol\r
    */\r
   /*\r
-  * Each symbol character is defined by an 8-digit bar-space sequence which\r
-  * represents the module widths of the eight elements of that symbol\r
-  * character.\r
-  */\r
-  private static long getSymbol(int[] counters, int rowNumber, float moduleWidth) {\r
+  private static long getSymbol(int[] counters, float moduleWidth) {\r
     int pixelsInSymbol = 0;\r
     for (int j = 0; j < counters.length; j++) {\r
       pixelsInSymbol += counters[j];\r
@@ -306,28 +297,25 @@ final class BitMatrixParser {
     }\r
     return symbol;\r
   }\r
+   */\r
 \r
   /**\r
    * Translate the symbol into a codeword.\r
    *\r
    * @param symbol\r
-   * @param row\r
    * @return the codeword corresponding to the symbol.\r
-   * @throws ReaderException\r
    */\r
-  private int getCodeword(long symbol, int row) throws ReaderException {\r
-\r
+  private int getCodeword(long symbol) {\r
     long sym = symbol;\r
     sym &= 0x3ffff;\r
     int i = findCodewordIndex(sym);\r
-    long cw = 0;\r
     if (i == -1) {\r
       return -1;\r
     } else {\r
-      cw = CODEWORD_TABLE[i] - 1;\r
+      long cw = CODEWORD_TABLE[i] - 1;\r
       cw %= 929;\r
+      return (int) cw;\r
     }\r
-    return (int) cw;\r
   }\r
 \r
   /**\r
@@ -337,11 +325,11 @@ final class BitMatrixParser {
    * @param symbol the symbol from the barcode.\r
    * @return the index into the codeword table.\r
    */\r
-  private int findCodewordIndex(long symbol) {\r
+  private static int findCodewordIndex(long symbol) {\r
     int first = 0;\r
     int upto = SYMBOL_TABLE.length;\r
     while (first < upto) {\r
-      int mid = (first + upto) / 2; // Compute mid point.\r
+      int mid = (first + upto) >>> 1; // Compute mid point.\r
       if (symbol < SYMBOL_TABLE[mid]) {\r
         upto = mid; // repeat search in bottom half.\r
       } else if (symbol > SYMBOL_TABLE[mid]) {\r
@@ -359,16 +347,11 @@ final class BitMatrixParser {
    * Ends up being a bit faster than Math.round(). This merely rounds its\r
    * argument to the nearest int, where x.5 rounds up.\r
    */\r
+  /*\r
   private static int round(float d) {\r
     return (int) (d + 0.5f);\r
   }\r
-\r
-  /**\r
-   * Returns the number of codewords flagged as erasures.\r
    */\r
-  public int getEraseCount() {\r
-    return eraseCount;\r
-  }\r
 \r
   /**\r
    * Returns an array of locations representing the erasures.\r
@@ -398,14 +381,15 @@ final class BitMatrixParser {
    *         this row.\r
    * @throws ReaderException\r
    */\r
+  /*\r
   int processRow1(int[] rowCounters, int rowNumber, int rowHeight,\r
-                  float moduleWidth, int[] codewords, int next) throws ReaderException {\r
+                  float moduleWidth, int[] codewords, int next) {\r
     int width = bitMatrix.getDimension();\r
     int firstBlack = 0;\r
 \r
     for (firstBlack = 0; firstBlack < width; firstBlack++) {\r
       // Step forward until we find the first black pixels\r
-      if (rowCounters[firstBlack] >= rowHeight / 2) {\r
+      if (rowCounters[firstBlack] >= rowHeight >>> 1) {\r
         break;\r
       }\r
     }\r
@@ -421,7 +405,7 @@ final class BitMatrixParser {
         // for\r
         // black\r
         // If more than half the column is black\r
-        if (rowCounters[i] >= rowHeight / 2 || i == width - 1) {\r
+        if (rowCounters[i] >= rowHeight >>> 1 || i == width - 1) {\r
           if (i == width - 1) {\r
             counters[state]++;\r
           }\r
@@ -435,7 +419,7 @@ final class BitMatrixParser {
           counters[state]++;\r
         }\r
       } else {\r
-        if (rowCounters[i] < rowHeight / 2) {\r
+        if (rowCounters[i] < rowHeight >>> 1) {\r
           // Found white pixels\r
           state++;\r
           if (state == 7 && i == width - 1) {\r
@@ -462,8 +446,8 @@ final class BitMatrixParser {
           return -1;\r
         }\r
         if (columnNumber > 0) {\r
-          symbol = getSymbol(counters, rowNumber, moduleWidth);\r
-          int cw = getCodeword(symbol, rowNumber);\r
+          symbol = getSymbol(counters, moduleWidth);\r
+          int cw = getCodeword(symbol);\r
           // if (debug) System.out.println(" " +\r
           // Long.toBinaryString(symbol) + " cw=" +cw + " ColumnNumber="\r
           // +columnNumber + "i=" +i);\r
@@ -476,8 +460,8 @@ final class BitMatrixParser {
           }\r
         } else {\r
           // Left row indicator column\r
-          symbol = getSymbol(counters, rowNumber, moduleWidth);\r
-          int cw = getCodeword(symbol, rowNumber);\r
+          symbol = getSymbol(counters, moduleWidth);\r
+          int cw = getCodeword(symbol);\r
           if (ecLevel < 0) {\r
             switch (rowNumber % 3) {\r
               case 0:\r
@@ -496,15 +480,13 @@ final class BitMatrixParser {
         counters = new int[8];\r
         columns = columnNumber;\r
         columnNumber++;\r
-        /*\r
-        * // Introduce some errors if (rowNumber == 0 && columnNumber == 4)\r
-        * { codewords[next-1] = 0; erasures[eraseCount] = next-1;\r
-        * eraseCount++; } if (rowNumber == 0 && columnNumber == 6) {\r
-        * codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
-        * eraseCount++; } if (rowNumber == 0 && columnNumber == 8) {\r
-        * codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
-        * eraseCount++; }\r
-        */\r
+        // Introduce some errors if (rowNumber == 0 && columnNumber == 4)\r
+        // { codewords[next-1] = 0; erasures[eraseCount] = next-1;\r
+        // eraseCount++; } if (rowNumber == 0 && columnNumber == 6) {\r
+        // codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
+        // eraseCount++; } if (rowNumber == 0 && columnNumber == 8) {\r
+        // codewords[next-1] = 10; erasures[eraseCount] = next-1;\r
+        // eraseCount++; }\r
         state = 0;\r
         symbol = 0;\r
       }\r
@@ -533,6 +515,7 @@ final class BitMatrixParser {
     }\r
     return next;\r
   }\r
+   */\r
 \r
   /**\r
    * The sorted table of all possible symbols. Extracted from the PDF417\r