Fixed some code which was ignoring the result of MonochromeBitmapSource calls, which...
[zxing.git] / core / src / com / google / zxing / Result.java
1 /*
2  * Copyright 2007 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;
18
19 import java.util.Hashtable;
20
21 /**
22  * <p>Encapsulates the result of decoding a barcode within an image.</p>
23  *
24  * @author Sean Owen
25  */
26 public final class Result {
27
28   private final String text;
29   private final byte[] rawBytes;
30   private final ResultPoint[] resultPoints;
31   private final BarcodeFormat format;
32   private Hashtable resultMetadata;
33
34   public Result(String text,
35                 byte[] rawBytes,
36                 ResultPoint[] resultPoints,
37                 BarcodeFormat format) {
38     if (text == null && rawBytes == null) {
39       throw new IllegalArgumentException("Text and bytes are null");
40     }
41     this.text = text;
42     this.rawBytes = rawBytes;
43     this.resultPoints = resultPoints;
44     this.format = format;
45     this.resultMetadata = null;
46   }
47
48   /**
49    * @return raw text encoded by the barcode, if applicable, otherwise <code>null</code>
50    */
51   public String getText() {
52     return text;
53   }
54
55   /**
56    * @return raw bytes encoded by the barcode, if applicable, otherwise <code>null</code>
57    */
58   public byte[] getRawBytes() {
59     return rawBytes;
60   }
61
62   /**
63    * @return points related to the barcode in the image. These are typically points
64    *         identifying finder patterns or the corners of the barcode. The exact meaning is
65    *         specific to the type of barcode that was decoded.
66    */
67   public ResultPoint[] getResultPoints() {
68     return resultPoints;
69   }
70
71   /**
72    * @return {@link BarcodeFormat} representing the format of the barcode that was decoded
73    */
74   public BarcodeFormat getBarcodeFormat() {
75     return format;
76   }
77
78   /**
79    * @return {@link Hashtable} mapping {@link ResultMetadataType} keys to values. May be
80    *   <code>null</code>. This contains optional metadata about what was detected about the barcode,
81    *   like orientation.
82    */
83   public Hashtable getResultMetadata() {
84     return resultMetadata;
85   }
86
87   public void putMetadata(ResultMetadataType type, Object value) {
88     if (resultMetadata == null) {
89       resultMetadata = new Hashtable(3);
90     }
91     resultMetadata.put(type, value);
92   }
93
94   public String toString() {
95     if (text == null) {
96       return "[" + rawBytes.length + " bytes]";
97     } else {
98       return text;
99     }
100   }
101
102 }