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.common;
19 import java.util.Vector;
22 * <p>This is basically a substitute for <code>java.util.Collections</code>, which is not
23 * present in MIDP 2.0 / CLDC 1.1.</p>
25 * @author srowen@google.com (Sean Owen)
27 public final class Collections {
29 private Collections() {
33 * Sorts its argument (destructively) using insert sort; in the context of this package
34 * insertion sort is simple and efficient given its relatively small inputs.
36 * @param vector vector to sort
37 * @param comparator comparator to define sort ordering
39 public static void insertionSort(Vector vector, Comparator comparator) {
40 int max = vector.size();
41 for (int i = 1; i < max; i++) {
42 Object value = vector.elementAt(i);
45 while (j >= 0 && comparator.compare((valueB = vector.elementAt(j)), value) > 0) {
46 vector.setElementAt(valueB, j + 1);
49 vector.setElementAt(value, j + 1);