diff 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
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ArrayHelper.java	Sun Jul 21 17:48:05 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/ArrayHelper.java	Mon Jul 22 22:47:06 2013 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 TMate Software Ltd
+ * Copyright (c) 2011-2013 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -89,7 +89,9 @@
 	 */
 	public int binarySearchSorted(T value) {
 		if (sorted != null) {
-			return Arrays.binarySearch(sorted, 0, data.length, value);
+			int x = Arrays.binarySearch(sorted, value);
+			// fulfill the Arrays#binarySearch contract in case sorted array is greater than data 
+			return x >= data.length ? -(data.length - 1) : x;
 		}
 		return binarySearchWithReverse(0, data.length, value);
 	}