Small style stuff
[zxing.git] / core / src / com / google / zxing / client / result / SMSParsedResult.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.client.result;
18
19 /**
20  * @author Sean Owen
21  */
22 public final class SMSParsedResult extends ParsedResult {
23
24   private final String[] numbers;
25   private final String[] vias;
26   private final String subject;
27   private final String body;
28
29   public SMSParsedResult(String number, String via, String subject, String body) {
30     super(ParsedResultType.SMS);
31     this.numbers = new String[] {number};
32     this.vias = new String[] {via};
33     this.subject = subject;
34     this.body = body;
35   }
36
37   public SMSParsedResult(String[] numbers, String[] vias, String subject, String body) {
38     super(ParsedResultType.SMS);
39     this.numbers = numbers;
40     this.vias = vias;
41     this.subject = subject;
42     this.body = body;
43   }
44
45   public String getSMSURI() {
46     StringBuffer result = new StringBuffer();
47     result.append("sms:");
48     boolean first = true;
49     for (int i = 0; i < numbers.length; i++) {
50       if (first) {
51         first = false;
52       } else {
53         result.append(',');
54       }
55       result.append(numbers[i]);
56       if (vias[i] != null) {
57         result.append(";via=");
58         result.append(vias[i]);
59       }
60     }
61     boolean hasBody = body != null;
62     boolean hasSubject = subject != null;
63     if (hasBody || hasSubject) {
64       result.append('?');
65       if (hasBody) {
66         result.append("body=");
67         result.append(body);
68       }
69       if (hasSubject) {
70         if (hasBody) {
71           result.append('&');
72         }
73         result.append("subject=");
74         result.append(subject);
75       }
76     }
77     return result.toString();
78   }
79
80   public String[] getNumbers() {
81     return numbers;
82   }
83
84   public String[] getVias() {
85     return vias;
86   }
87
88   public String getSubject() {
89     return subject;
90   }
91
92   public String getBody() {
93     return body;
94   }
95
96   public String getDisplayResult() {
97     StringBuffer result = new StringBuffer(100);
98     maybeAppend(numbers, result);
99     maybeAppend(subject, result);
100     maybeAppend(body, result);
101     return result.toString();
102   }
103
104 }