Used IntelliJ's amazing refactoring functions to change the argument ordering of...
[zxing.git] / core / src / com / google / zxing / oned / Code39Reader.java
index 4d69d6b..fe93251 100644 (file)
@@ -21,14 +21,13 @@ import com.google.zxing.ReaderException;
 import com.google.zxing.Result;
 import com.google.zxing.ResultPoint;
 import com.google.zxing.common.BitArray;
-import com.google.zxing.common.GenericResultPoint;
 
 import java.util.Hashtable;
 
 /**
  * <p>Decodes Code 39 barcodes. This does not support "Full ASCII Code 39" yet.</p>
  *
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
  */
 public final class Code39Reader extends AbstractOneDReader {
 
@@ -92,9 +91,7 @@ public final class Code39Reader extends AbstractOneDReader {
   public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
 
     int[] start = findAsteriskPattern(row);
-
     int nextStart = start[1];
-
     int end = row.getSize();
 
     // Read off white space
@@ -131,7 +128,7 @@ public final class Code39Reader extends AbstractOneDReader {
     // If 50% of last pattern size, following last pattern, is not whitespace, fail
     // (but if it's whitespace to the very end of the image, that's OK)
     if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) {
-      throw new ReaderException("Pattern not followed by whitespace");
+      throw ReaderException.getInstance();
     }
 
     if (usingCheckDigit) {
@@ -141,7 +138,7 @@ public final class Code39Reader extends AbstractOneDReader {
         total += ALPHABET_STRING.indexOf(result.charAt(i));
       }
       if (total % 43 != ALPHABET_STRING.indexOf(result.charAt(max))) {
-        throw new ReaderException("Checksum failed");
+        throw ReaderException.getInstance();
       }
       result.deleteCharAt(max);
     }
@@ -153,7 +150,7 @@ public final class Code39Reader extends AbstractOneDReader {
 
     if (resultString.length() == 0) {
       // Almost surely a false positive
-      throw new ReaderException("Empty barcode found; assuming a false positive");
+      throw ReaderException.getInstance();
     }
 
     float left = (float) (start[1] + start[0]) / 2.0f;
@@ -162,8 +159,8 @@ public final class Code39Reader extends AbstractOneDReader {
         resultString,
         null,
         new ResultPoint[]{
-            new GenericResultPoint(left, (float) rowNumber),
-            new GenericResultPoint(right, (float) rowNumber)},
+            new ResultPoint(left, (float) rowNumber),
+            new ResultPoint(right, (float) rowNumber)},
         BarcodeFormat.CODE_39);
 
   }
@@ -186,7 +183,7 @@ public final class Code39Reader extends AbstractOneDReader {
 
     for (int i = rowOffset; i < width; i++) {
       boolean pixel = row.get(i);
-      if ((!pixel && isWhite) || (pixel && !isWhite)) {
+      if (pixel ^ isWhite) {
         counters[counterPosition]++;
       } else {
         if (counterPosition == patternLength - 1) {
@@ -211,10 +208,10 @@ public final class Code39Reader extends AbstractOneDReader {
           counterPosition++;
         }
         counters[counterPosition] = 1;
-        isWhite = !isWhite;
+        isWhite ^= true; // isWhite = !isWhite;
       }
     }
-    throw new ReaderException("Can't find pattern");
+    throw ReaderException.getInstance();
   }
 
   private static int toNarrowWidePattern(int[] counters) throws ReaderException {
@@ -251,14 +248,14 @@ public final class Code39Reader extends AbstractOneDReader {
             wideCounters--;
             // totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average
             if ((counter << 1) >= totalWideCountersWidth) {
-              throw new ReaderException("Wide bars vary too much in width, rejecting");
+              throw ReaderException.getInstance();
             }
           }
         }
         return pattern;
       }
     } while (wideCounters > 3);
-    throw new ReaderException("Can't find 3 wide bars/spaces out of 9");
+    throw ReaderException.getInstance();
   }
 
   private static char patternToChar(int pattern) throws ReaderException {
@@ -267,7 +264,7 @@ public final class Code39Reader extends AbstractOneDReader {
         return ALPHABET[i];
       }
     }
-    throw new ReaderException("Pattern did not match character encoding");
+    throw ReaderException.getInstance();
   }
 
   private static String decodeExtended(String encoded) throws ReaderException {
@@ -284,7 +281,7 @@ public final class Code39Reader extends AbstractOneDReader {
             if (next >= 'A' && next <= 'Z') {
               decodedChar = (char) (next + 32);
             } else {
-              throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
+              throw ReaderException.getInstance();
             }
             break;
           case '$':
@@ -292,7 +289,7 @@ public final class Code39Reader extends AbstractOneDReader {
             if (next >= 'A' && next <= 'Z') {
               decodedChar = (char) (next - 64);
             } else {
-              throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
+              throw ReaderException.getInstance();
             }
             break;
           case '%':
@@ -302,7 +299,7 @@ public final class Code39Reader extends AbstractOneDReader {
             } else if (next >= 'F' && next <= 'W') {
               decodedChar = (char) (next - 11);
             } else {
-              throw new ReaderException("Invalid extended code 39 sequence: " + c + next);
+              throw ReaderException.getInstance();
             }
             break;
           case '/':
@@ -312,7 +309,7 @@ public final class Code39Reader extends AbstractOneDReader {
             } else if (next == 'Z') {
               decodedChar = ':';
             } else {
-              throw new ReaderException("Invalid extended sequence: " + c + next);
+              throw ReaderException.getInstance();
             }
             break;
         }