Turned on ITF as a format you can request via hint. Also rejiggered the unit test...
[zxing.git] / core / src / com / google / zxing / oned / MultiFormatOneDReader.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.oned;
18
19 import com.google.zxing.DecodeHintType;
20 import com.google.zxing.ReaderException;
21 import com.google.zxing.Result;
22 import com.google.zxing.BarcodeFormat;
23 import com.google.zxing.common.BitArray;
24
25 import java.util.Hashtable;
26 import java.util.Vector;
27
28 /**
29  * @author dswitkin@google.com (Daniel Switkin)
30  * @author Sean Owen
31  */
32 public final class MultiFormatOneDReader extends AbstractOneDReader {
33
34   private final Vector readers;
35
36   public MultiFormatOneDReader(Hashtable hints) {
37     Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
38     readers = new Vector();
39     if (possibleFormats != null) {
40       if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
41           possibleFormats.contains(BarcodeFormat.UPC_A) ||
42           possibleFormats.contains(BarcodeFormat.EAN_8) ||
43           possibleFormats.contains(BarcodeFormat.UPC_E)) {
44         readers.addElement(new MultiFormatUPCEANReader(hints));
45       }
46       if (possibleFormats.contains(BarcodeFormat.CODE_39)) {
47         readers.addElement(new Code39Reader());
48       }
49       if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
50         readers.addElement(new Code128Reader());
51       }
52       if (possibleFormats.contains(BarcodeFormat.ITF)) {
53          readers.addElement(new ITFReader());
54       }
55     }
56     if (readers.isEmpty()) {
57       readers.addElement(new MultiFormatUPCEANReader(hints));
58       readers.addElement(new Code39Reader());
59       readers.addElement(new Code128Reader());
60       // TODO: Add ITFReader once it is validated as production ready, and tested for performance.
61       //readers.addElement(new ITFReader());
62     }
63   }
64
65   public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {
66     int size = readers.size();
67     for (int i = 0; i < size; i++) {
68       OneDReader reader = (OneDReader) readers.elementAt(i);
69       try {
70         return reader.decodeRow(rowNumber, row, hints);
71       } catch (ReaderException re) {
72         // continue
73       }
74     }
75
76     throw ReaderException.getInstance();
77   }
78
79 }