changeset 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 4f93bbc73b64
children 98ff1fb49abe
files src/org/tmatesoft/hg/internal/ArrayHelper.java src/org/tmatesoft/hg/internal/EncodingHelper.java src/org/tmatesoft/hg/internal/diff/DiffRangeMap.java
diffstat 3 files changed, 14 insertions(+), 4 deletions(-) [+]
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);
 	}
--- a/src/org/tmatesoft/hg/internal/EncodingHelper.java	Sun Jul 21 17:48:05 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/EncodingHelper.java	Mon Jul 22 22:47:06 2013 +0200
@@ -180,7 +180,11 @@
 			return utfDecoder.decode(ByteBuffer.wrap(data, start, length)).toString();
 		} catch (CharacterCodingException ex) {
 			// TODO post-1.2 respect ui.fallbackencoding actual setting
-			return new String(data, start, length, Charset.forName("ISO-8859-1"));
+			try {
+				return new String(data, start, length, "ISO-8859-1"); // XXX java5
+			} catch (UnsupportedEncodingException e) {
+				throw new HgInvalidStateException(ex.getMessage());
+			}
 		}
 	}
 	
--- a/src/org/tmatesoft/hg/internal/diff/DiffRangeMap.java	Sun Jul 21 17:48:05 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/diff/DiffRangeMap.java	Mon Jul 22 22:47:06 2013 +0200
@@ -19,6 +19,7 @@
 import java.util.ArrayList;
 
 import org.tmatesoft.hg.internal.DiffHelper;
+import org.tmatesoft.hg.internal.DiffHelper.MatchInspector;
 import org.tmatesoft.hg.internal.IntSliceSeq;
 import org.tmatesoft.hg.internal.IntTuple;
 import org.tmatesoft.hg.internal.DiffHelper.ChunkSequence;
@@ -44,8 +45,11 @@
 	 *   dh.findMatchingBlocks(p1ToBase); // compiles ok!
 	 * </pre>
 	 */
+	@SuppressWarnings("unchecked")
 	public DiffRangeMap fill(DiffHelper<?> dh) {
-		dh.findMatchingBlocks(this);
+		@SuppressWarnings("rawtypes")
+		final MatchInspector i = (MatchInspector) this;
+		dh.findMatchingBlocks(i);
 		return this;
 	}