Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 34 lines 1.2 kB view raw
1package org.bukkit.craftbukkit.util; 2 3import java.lang.reflect.Array; 4 5public class Java15Compat { 6 public static <T> T[] Arrays_copyOf(T[] original, int newLength) { 7 if (0 <= newLength) { 8 return org.bukkit.util.Java15Compat.Arrays_copyOfRange(original, 0, newLength); 9 } 10 throw new NegativeArraySizeException(); 11 } 12 13 public static long[] Arrays_copyOf(long[] original, int newLength) { 14 if (0 <= newLength) { 15 return Arrays_copyOfRange(original, 0, newLength); 16 } 17 throw new NegativeArraySizeException(); 18 } 19 20 private static long[] Arrays_copyOfRange(long[] original, int start, int end) { 21 if (original.length >= start && 0 <= start) { 22 if (start <= end) { 23 int length = end - start; 24 int copyLength = Math.min(length, original.length - start); 25 long[] copy = (long[]) Array.newInstance(original.getClass().getComponentType(), length); 26 System.arraycopy(original, start, copy, 0, copyLength); 27 return copy; 28 } 29 throw new IllegalArgumentException(); 30 } 31 throw new ArrayIndexOutOfBoundsException(); 32 } 33 34}