Java 1.5 compat.

By: Erik Broes <erikbroes@ripe.net>
This commit is contained in:
Bukkit/Spigot
2011-03-02 15:23:15 +01:00
parent 2d93fec7d2
commit 6410e49ab9
3 changed files with 24 additions and 3 deletions

View File

@@ -0,0 +1,20 @@
package org.bukkit.util;
import java.lang.reflect.Array;
public class Java15Compat {
@SuppressWarnings("unchecked")
public static <T> T[] Arrays_copyOfRange(T[] original, int start, int end) {
if (original.length >= start && 0 <= start) {
if (start <= end) {
int length = end - start;
int copyLength = Math.min( length, original.length - start);
T[] copy = (T[]) Array.newInstance(original.getClass().getComponentType(), length);
System.arraycopy(original, start, copy, 0, copyLength);
return copy;
}
throw new IllegalArgumentException();
}
throw new ArrayIndexOutOfBoundsException();
}
}