Added Code 39 check digit hint
[zxing.git] / core / src / com / google / zxing / oned / MultiFormatOneDReader.java
index df47b89..c22437b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008 Google Inc.
+ * Copyright 2008 ZXing authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,35 +27,44 @@ import java.util.Vector;
 
 /**
  * @author dswitkin@google.com (Daniel Switkin)
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
  */
 public final class MultiFormatOneDReader extends AbstractOneDReader {
 
-  public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+  private final Vector readers;
 
+  public MultiFormatOneDReader(Hashtable hints) {
     Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
-    Vector readers = new Vector();
+    boolean useCode39CheckDigit = hints != null && hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
+    readers = new Vector();
     if (possibleFormats != null) {
       if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
           possibleFormats.contains(BarcodeFormat.UPC_A) ||
           possibleFormats.contains(BarcodeFormat.EAN_8) ||
           possibleFormats.contains(BarcodeFormat.UPC_E)) {
-        readers.addElement(new MultiFormatUPCEANReader());
+        readers.addElement(new MultiFormatUPCEANReader(hints));
       }
       if (possibleFormats.contains(BarcodeFormat.CODE_39)) {
-        readers.addElement(new Code39Reader());
+        readers.addElement(new Code39Reader(useCode39CheckDigit));
       }
       if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
         readers.addElement(new Code128Reader());
       }
+      if (possibleFormats.contains(BarcodeFormat.ITF)) {
+         readers.addElement(new ITFReader());
+      }
     }
     if (readers.isEmpty()) {
-      readers.addElement(new MultiFormatUPCEANReader());
+      readers.addElement(new MultiFormatUPCEANReader(hints));
       readers.addElement(new Code39Reader());
       readers.addElement(new Code128Reader());
+      readers.addElement(new ITFReader());
     }
+  }
 
-    for (int i = 0; i < readers.size(); i++) {
+  public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
+    int size = readers.size();
+    for (int i = 0; i < size; i++) {
       OneDReader reader = (OneDReader) readers.elementAt(i);
       try {
         return reader.decodeRow(rowNumber, row, hints);
@@ -64,7 +73,7 @@ public final class MultiFormatOneDReader extends AbstractOneDReader {
       }
     }
 
-    throw new ReaderException("No barcode was detected in this image.");
+    throw ReaderException.getInstance();
   }
 
-}
\ No newline at end of file
+}