comparison src/org/tmatesoft/hg/internal/ArrayHelper.java @ 682:f568330dd9c0

Compile with Java5, ensure generics are fine for other compilers, too
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 22 Jul 2013 22:47:06 +0200
parents d10399f80f4e
children
comparison
equal deleted inserted replaced
681:4f93bbc73b64 682:f568330dd9c0
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2013 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
87 * Look up sorted index of the value, using sort information 87 * Look up sorted index of the value, using sort information
88 * @return same value as {@link Arrays#binarySearch(Object[], Object)} does 88 * @return same value as {@link Arrays#binarySearch(Object[], Object)} does
89 */ 89 */
90 public int binarySearchSorted(T value) { 90 public int binarySearchSorted(T value) {
91 if (sorted != null) { 91 if (sorted != null) {
92 return Arrays.binarySearch(sorted, 0, data.length, value); 92 int x = Arrays.binarySearch(sorted, value);
93 // fulfill the Arrays#binarySearch contract in case sorted array is greater than data
94 return x >= data.length ? -(data.length - 1) : x;
93 } 95 }
94 return binarySearchWithReverse(0, data.length, value); 96 return binarySearchWithReverse(0, data.length, value);
95 } 97 }
96 98
97 /** 99 /**