/*
 * Copyright 2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.zxing;

import com.google.zxing.oned.MultiFormatOneDReader;
import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.datamatrix.DataMatrixReader;

import java.util.Hashtable;
import java.util.Vector;

/**
 * <p>This implementation can detect barcodes in one of several formats within
 * an image, and then decode what it finds. This implementation supports all
 * barcode formats that this library supports.</p>
 *
 * @author srowen@google.com (Sean Owen), dswitkin@google.com (Daniel Switkin)
 */
public final class MultiFormatReader implements Reader {

  public Result decode(MonochromeBitmapSource image) throws ReaderException {
    return decode(image, null);
  }

  public Result decode(MonochromeBitmapSource image, Hashtable hints) throws ReaderException {

    boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
    Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
    Vector readers = new Vector();
    if (possibleFormats != null) {
      boolean addOneDReader =
          possibleFormats.contains(BarcodeFormat.UPC_A) ||
          possibleFormats.contains(BarcodeFormat.UPC_E) ||
          possibleFormats.contains(BarcodeFormat.EAN_13) ||
          possibleFormats.contains(BarcodeFormat.EAN_8) ||
          possibleFormats.contains(BarcodeFormat.CODE_39) ||
          possibleFormats.contains(BarcodeFormat.CODE_128);
      // Put 1D readers upfront in "normal" mode
      if (addOneDReader && !tryHarder) {
        readers.addElement(new MultiFormatOneDReader());
      }
      if (possibleFormats.contains(BarcodeFormat.QR_CODE)) {
        readers.addElement(new QRCodeReader());
      }
      if (possibleFormats.contains(BarcodeFormat.DATAMATRIX)) {
        readers.addElement(new DataMatrixReader());
      }
      // At end in "try harder" mode
      if (addOneDReader && tryHarder) {
        readers.addElement(new MultiFormatOneDReader());
      }
    }
    if (readers.isEmpty()) {
      if (!tryHarder) {
        readers.addElement(new MultiFormatOneDReader());
      }
      readers.addElement(new QRCodeReader());
      // TODO re-enable once Data Matrix is ready
      // readers.addElement(new DataMatrixReader());
      if (tryHarder) {
        readers.addElement(new MultiFormatOneDReader());
      }
    }

    for (int i = 0; i < readers.size(); i++) {
      Reader reader = (Reader) readers.elementAt(i);
      try {
        return reader.decode(image, hints);
      } catch (ReaderException re) {
        // continue
      }
    }

    throw new ReaderException("No barcode was detected in this image.");
  }

}

@@ -717,61 +717,8 @@
 der;
-%0Aimport com.google.zxing.datamatrix.DataMatrixReader;
 %0A%0Aim
@@ -2255,32 +2255,84 @@
 ;%0A      %7D%0A      
+// TODO re-enable once Data Matrix is ready%0A      //
 if (possibleForm
@@ -2371,32 +2371,34 @@
 ATRIX)) %7B%0A      
+//
   readers.addEle
@@ -2425,32 +2425,34 @@
 eader());%0A      
+//
 %7D%0A      // At en

Remove compile-time reference to DataMatrixReader