More small changes from code inspection
[zxing.git] / core / src / com / google / zxing / oned / AbstractUPCEANReader.java
index 83aa7c0..5336e0d 100644 (file)
@@ -86,7 +86,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
 
   private final StringBuffer decodeRowStringBuffer;
 
-  public AbstractUPCEANReader() {
+  protected AbstractUPCEANReader() {
     decodeRowStringBuffer = new StringBuffer(20);
   }
 
@@ -124,12 +124,12 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
     int end = endRange[1];
     int quietEnd = end + (end - endRange[0]);
     if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) {
-      throw new ReaderException("Pattern not followed by whitespace");
+      throw ReaderException.getInstance();
     }
 
     String resultString = result.toString();
     if (!checkChecksum(resultString)) {
-      throw new ReaderException("Checksum failed");
+      throw ReaderException.getInstance();
     }
 
     float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
@@ -144,6 +144,13 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
 
   abstract BarcodeFormat getBarcodeFormat();
 
+  /**
+   * @return {@link #checkStandardUPCEANChecksum(String)} 
+   */
+  boolean checkChecksum(String s) throws ReaderException {
+    return checkStandardUPCEANChecksum(s);
+  }
+
   /**
    * Computes the UPC/EAN checksum on a string of digits, and reports
    * whether the checksum is correct or not.
@@ -152,7 +159,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
    * @return true iff string of digits passes the UPC/EAN checksum algorithm
    * @throws ReaderException if the string does not contain only digits
    */
-  boolean checkChecksum(String s) throws ReaderException {
+  public static boolean checkStandardUPCEANChecksum(String s) throws ReaderException {
     int length = s.length();
     if (length == 0) {
       return false;
@@ -162,7 +169,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
     for (int i = length - 2; i >= 0; i -= 2) {
       int digit = (int) s.charAt(i) - (int) '0';
       if (digit < 0 || digit > 9) {
-        throw new ReaderException("Illegal character during checksum");
+        throw ReaderException.getInstance();
       }
       sum += digit;
     }
@@ -170,7 +177,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
     for (int i = length - 1; i >= 0; i -= 2) {
       int digit = (int) s.charAt(i) - (int) '0';
       if (digit < 0 || digit > 9) {
-        throw new ReaderException("Illegal character during checksum");
+        throw ReaderException.getInstance();
       }
       sum += digit;
     }
@@ -242,7 +249,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
         isWhite = !isWhite;
       }
     }
-    throw new ReaderException("Can't find pattern");
+    throw ReaderException.getInstance();
   }
 
   /**
@@ -274,7 +281,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
     if (bestMatch >= 0) {
       return bestMatch;
     } else {
-      throw new ReaderException("Could not match any digit in pattern");
+      throw ReaderException.getInstance();
     }
   }