Committed C# port from Mohamad
[zxing.git] / csharp / common / Collections.cs
1 /*\r
2 * Copyright 2008 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 namespace com.google.zxing.common\r
17 {\r
18     using System;\r
19     using System.Text;\r
20 \r
21     /// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a\r
22     /// unsigned container, it's up to you to do byteValue & 0xff at each location.\r
23     /// *\r
24     /// JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have\r
25     /// the horizontal component first, but this is for compatibility with the C++ code. The original\r
26     /// code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use\r
27     /// less memory and go with bytes.\r
28     /// *\r
29     /// </summary>\r
30     /// <author>  dswitkin@google.com (Daniel Switkin)\r
31     /// \r
32     /// </author>\r
33     public sealed class Collections\r
34     {\r
35 \r
36         private Collections()\r
37         {\r
38         }\r
39 \r
40         /**\r
41          * Sorts its argument (destructively) using insert sort; in the context of this package\r
42          * insertion sort is simple and efficient given its relatively small inputs.\r
43          *\r
44          * @param vector vector to sort\r
45          * @param comparator comparator to define sort ordering\r
46          */\r
47         public static void insertionSort(System.Collections.ArrayList vector, Comparator comparator)\r
48         {\r
49             int max = vector.Count;\r
50                         for (int i = 1; i < max; i++)\r
51                         {\r
52                                 System.Object value_Renamed = vector[i];\r
53                                 int j = i - 1;\r
54                                 System.Object valueB;\r
55                                 while (j >= 0 && comparator.compare((valueB = vector[j]), value_Renamed) > 0)\r
56                                 {\r
57                                         vector[j + 1] = valueB;\r
58                                         j--;\r
59                                 }\r
60                                 vector[j + 1] = value_Renamed;\r
61                         }\r
62         }\r
63     }\r
64 }