Issue 521, avoid an NPE
[zxing.git] / csharp / Result.cs
1 /*\r
2 * Copyright 2007 ZXing authors\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16 using System;\r
17 namespace com.google.zxing\r
18 {\r
19         \r
20         /// <summary> <p>Encapsulates the result of decoding a barcode within an image.</p>\r
21         /// \r
22         /// </summary>\r
23         /// <author>  Sean Owen\r
24         /// </author>\r
25         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
26         /// </author>\r
27 \r
28         public sealed class Result\r
29         {\r
30                 /// <returns> raw text encoded by the barcode, if applicable, otherwise <code>null</code>\r
31                 /// </returns>\r
32                 public System.String Text\r
33                 {\r
34                         get\r
35                         {\r
36                                 return text;\r
37                         }\r
38                         \r
39                 }\r
40                 /// <returns> raw bytes encoded by the barcode, if applicable, otherwise <code>null</code>\r
41                 /// </returns>\r
42                 public sbyte[] RawBytes\r
43                 {\r
44                         get\r
45                         {\r
46                                 return rawBytes;\r
47                         }\r
48                         \r
49                 }\r
50                 /// <returns> points related to the barcode in the image. These are typically points\r
51                 /// identifying finder patterns or the corners of the barcode. The exact meaning is\r
52                 /// specific to the type of barcode that was decoded.\r
53                 /// </returns>\r
54                 public ResultPoint[] ResultPoints\r
55                 {\r
56                         get\r
57                         {\r
58                                 return resultPoints;\r
59                         }\r
60                         \r
61                 }\r
62                 /// <returns> {@link BarcodeFormat} representing the format of the barcode that was decoded\r
63                 /// </returns>\r
64                 public BarcodeFormat BarcodeFormat\r
65                 {\r
66                         get\r
67                         {\r
68                                 return format;\r
69                         }\r
70                         \r
71                 }\r
72                 /// <returns> {@link Hashtable} mapping {@link ResultMetadataType} keys to values. May be\r
73                 /// <code>null</code>. This contains optional metadata about what was detected about the barcode,\r
74                 /// like orientation.\r
75                 /// </returns>\r
76                 public System.Collections.Hashtable ResultMetadata\r
77                 {\r
78                         get\r
79                         {\r
80                                 return resultMetadata;\r
81                         }\r
82                         \r
83                 }\r
84                 \r
85                 //UPGRADE_NOTE: Final was removed from the declaration of 'text '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
86                 private System.String text;\r
87                 //UPGRADE_NOTE: Final was removed from the declaration of 'rawBytes '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
88                 private sbyte[] rawBytes;\r
89                 //UPGRADE_NOTE: Final was removed from the declaration of 'resultPoints '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
90                 private ResultPoint[] resultPoints;\r
91                 //UPGRADE_NOTE: Final was removed from the declaration of 'format '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
92                 private BarcodeFormat format;\r
93                 private System.Collections.Hashtable resultMetadata;\r
94                 \r
95                 public Result(System.String text, sbyte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format)\r
96                 {\r
97                         if (text == null && rawBytes == null)\r
98                         {\r
99                                 throw new System.ArgumentException("Text and bytes are null");\r
100                         }\r
101                         this.text = text;\r
102                         this.rawBytes = rawBytes;\r
103                         this.resultPoints = resultPoints;\r
104                         this.format = format;\r
105                         this.resultMetadata = null;\r
106                 }\r
107                 \r
108                 public void  putMetadata(ResultMetadataType type, System.Object value_Renamed)\r
109                 {\r
110                         if (resultMetadata == null)\r
111                         {\r
112                                 resultMetadata = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable(3));\r
113                         }\r
114                         resultMetadata[type] = value_Renamed;\r
115                 }\r
116                 \r
117                 public override System.String ToString()\r
118                 {\r
119                         if (text == null)\r
120                         {\r
121                                 return "[" + rawBytes.Length + " bytes]";\r
122                         }\r
123                         else\r
124                         {\r
125                                 return text;\r
126                         }\r
127                 }\r
128         }\r
129 }