Issue 521, avoid an NPE
[zxing.git] / csharp / common / Collections.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.common\r
18 {\r
19         \r
20         /// <summary> <p>This is basically a substitute for <code>java.util.Collections</code>, which is not\r
21         /// present in MIDP 2.0 / CLDC 1.1.</p>\r
22         /// \r
23         /// </summary>\r
24         /// <author>  Sean Owen\r
25         /// </author>\r
26         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
27         /// </author>\r
28         public sealed class Collections\r
29         {\r
30                 \r
31                 private Collections()\r
32                 {\r
33                 }\r
34                 \r
35                 /// <summary> Sorts its argument (destructively) using insert sort; in the context of this package\r
36                 /// insertion sort is simple and efficient given its relatively small inputs.\r
37                 /// \r
38                 /// </summary>\r
39                 /// <param name="vector">vector to sort\r
40                 /// </param>\r
41                 /// <param name="comparator">comparator to define sort ordering\r
42                 /// </param>\r
43                 public static void  insertionSort(System.Collections.ArrayList vector, Comparator comparator)\r
44                 {\r
45                         int max = vector.Count;\r
46                         for (int i = 1; i < max; i++)\r
47                         {\r
48                                 System.Object value_Renamed = vector[i];\r
49                                 int j = i - 1;\r
50                                 System.Object valueB;\r
51                                 while (j >= 0 && comparator.compare((valueB = vector[j]), value_Renamed) > 0)\r
52                                 {\r
53                                         vector[j + 1] = valueB;\r
54                                         j--;\r
55                                 }\r
56                                 vector[j + 1] = value_Renamed;\r
57                         }\r
58                 }\r
59         }\r
60 }