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.EnumMap;
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 ResultPoint[] resultPoints;
32 private final BarcodeFormat format;
33 private Map<ResultMetadataType,Object> 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,
49 this.rawBytes = rawBytes;
50 this.resultPoints = resultPoints;
52 this.resultMetadata = null;
53 this.timestamp = timestamp;
57 * @return raw text encoded by the barcode
59 public String getText() {
64 * @return raw bytes encoded by the barcode, if applicable, otherwise {@code null}
66 public byte[] getRawBytes() {
71 * @return points related to the barcode in the image. These are typically points
72 * identifying finder patterns or the corners of the barcode. The exact meaning is
73 * specific to the type of barcode that was decoded.
75 public ResultPoint[] getResultPoints() {
80 * @return {@link BarcodeFormat} representing the format of the barcode that was decoded
82 public BarcodeFormat getBarcodeFormat() {
87 * @return {@link Map} mapping {@link ResultMetadataType} keys to values. May be
88 * {@code null}. This contains optional metadata about what was detected about the barcode,
91 public Map<ResultMetadataType,Object> getResultMetadata() {
92 return resultMetadata;
95 public void putMetadata(ResultMetadataType type, Object value) {
96 if (resultMetadata == null) {
97 resultMetadata = new EnumMap<ResultMetadataType, Object>(ResultMetadataType.class);
99 resultMetadata.put(type, value);
102 public void putAllMetadata(Map<ResultMetadataType,Object> metadata) {
103 if (metadata != null) {
104 if (resultMetadata == null) {
105 resultMetadata = metadata;
107 resultMetadata.putAll(metadata);
112 public void addResultPoints(ResultPoint[] newPoints) {
113 ResultPoint[] oldPoints = resultPoints;
114 if (oldPoints == null) {
115 resultPoints = newPoints;
116 } else if (newPoints != null && newPoints.length > 0) {
117 ResultPoint[] allPoints = new ResultPoint[oldPoints.length + newPoints.length];
118 System.arraycopy(oldPoints, 0, allPoints, 0, oldPoints.length);
119 System.arraycopy(newPoints, 0, allPoints, oldPoints.length, newPoints.length);
120 resultPoints = allPoints;
124 public long getTimestamp() {
129 public String toString() {