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.client.result;
19 import com.google.zxing.Result;
22 * <p>Abstract class representing the result of decoding a barcode, as more than
23 * a String -- as some type of structured data. This might be a subclass which represents
24 * a URL, or an e-mail address. {@link ResultParser#parseResult(Result)} will turn a raw
25 * decoded string into the most appropriate type of structured representation.</p>
27 * <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
28 * on exception-based mechanisms during parsing.</p>
32 public abstract class ParsedResult {
34 private final ParsedResultType type;
36 protected ParsedResult(ParsedResultType type) {
40 public ParsedResultType getType() {
44 public abstract String getDisplayResult();
46 public String toString() {
47 return getDisplayResult();
50 public static void maybeAppend(String value, StringBuffer result) {
51 if (value != null && value.length() > 0) {
52 // Don't add a newline before the first value
53 if (result.length() > 0) {
60 public static void maybeAppend(String[] value, StringBuffer result) {
62 for (int i = 0; i < value.length; i++) {
63 if (value[i] != null && value[i].length() > 0) {
64 if (result.length() > 0) {
67 result.append(value[i]);