2 * Copyright 2007 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing;
19 import java.util.Enumeration;
20 import java.util.Hashtable;
23 * <p>Encapsulates the result of decoding a barcode within an image.</p>
27 public final class Result {
29 private final String text;
30 private final byte[] rawBytes;
31 private final ResultPoint[] resultPoints;
32 private final BarcodeFormat format;
33 private Hashtable resultMetadata;
34 private final long timestamp;
36 public Result(String text,
38 ResultPoint[] resultPoints,
39 BarcodeFormat format) {
40 this(text, rawBytes, resultPoints, format, System.currentTimeMillis());
43 public Result(String text,
45 ResultPoint[] resultPoints,
48 if (text == null && rawBytes == null) {
49 throw new IllegalArgumentException("Text and bytes are null");
52 this.rawBytes = rawBytes;
53 this.resultPoints = resultPoints;
55 this.resultMetadata = null;
56 this.timestamp = timestamp;
60 * @return raw text encoded by the barcode, if applicable, otherwise <code>null</code>
62 public String getText() {
67 * @return raw bytes encoded by the barcode, if applicable, otherwise <code>null</code>
69 public byte[] getRawBytes() {
74 * @return points related to the barcode in the image. These are typically points
75 * identifying finder patterns or the corners of the barcode. The exact meaning is
76 * specific to the type of barcode that was decoded.
78 public ResultPoint[] getResultPoints() {
83 * @return {@link BarcodeFormat} representing the format of the barcode that was decoded
85 public BarcodeFormat getBarcodeFormat() {
90 * @return {@link Hashtable} mapping {@link ResultMetadataType} keys to values. May be
91 * <code>null</code>. This contains optional metadata about what was detected about the barcode,
94 public Hashtable getResultMetadata() {
95 return resultMetadata;
98 public void putMetadata(ResultMetadataType type, Object value) {
99 if (resultMetadata == null) {
100 resultMetadata = new Hashtable(3);
102 resultMetadata.put(type, value);
105 public void putAllMetadata(Hashtable metadata) {
106 if (metadata != null) {
107 if (resultMetadata == null) {
108 resultMetadata = metadata;
110 Enumeration e = metadata.keys();
111 while (e.hasMoreElements()) {
112 ResultMetadataType key = (ResultMetadataType) e.nextElement();
113 Object value = metadata.get(key);
114 resultMetadata.put(key, value);
120 public long getTimestamp() {
124 public String toString() {
126 return "[" + rawBytes.length + " bytes]";