3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

Java 1.5 compat.

Dieser Commit ist enthalten in:
Erik Broes 2011-03-02 15:22:45 +01:00
Ursprung 87dc04b750
Commit 9d9ad6bd1e
3 geänderte Dateien mit 40 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,34 @@
package org.bukkit.craftbukkit.util;
import java.lang.reflect.Array;
public class Java15Compat {
public static <T> T[] Arrays_copyOf(T[] original, int newLength) {
if (0 <= newLength) {
return org.bukkit.util.Java15Compat.Arrays_copyOfRange(original, 0, newLength);
}
throw new NegativeArraySizeException();
}
public static long[] Arrays_copyOf(long[] original, int newLength) {
if (0 <= newLength) {
return Arrays_copyOfRange(original, 0, newLength);
}
throw new NegativeArraySizeException();
}
private static long[] Arrays_copyOfRange(long[] 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);
long[] copy = (long[]) Array.newInstance(original.getClass().getComponentType(), length);
System.arraycopy(original, start, copy, 0, copyLength);
return copy;
}
throw new IllegalArgumentException();
}
throw new ArrayIndexOutOfBoundsException();
}
}

Datei anzeigen

@ -1,5 +1,5 @@
package org.bukkit.craftbukkit.util;
import java.util.Arrays;
import static org.bukkit.craftbukkit.util.Java15Compat.Arrays_copyOf;
public class LongHashset extends LongHash {
long values[][][] = new long[256][][];
@ -31,7 +31,7 @@ public class LongHashset extends LongHash {
return;
}
}
outer[outerIdx] = inner = Arrays.copyOf(inner, i+1);
outer[outerIdx] = inner = Arrays_copyOf(inner, i+1);
inner[i] = key;
count++;
}
@ -66,7 +66,7 @@ public class LongHashset extends LongHash {
if(i != max) {
inner[i] = inner[max];
}
outer[(int) ((key >> 32) & 255)] = (max == 0 ? null : Arrays.copyOf(inner, max));
outer[(int) ((key >> 32) & 255)] = (max == 0 ? null : Arrays_copyOf(inner, max));
return;
}
}
@ -80,7 +80,7 @@ public class LongHashset extends LongHash {
if(inner == null || inner.length == 0) continue;
count--;
long ret = inner[inner.length - 1];
outer[i] = Arrays.copyOf(inner, inner.length - 1);
outer[i] = Arrays_copyOf(inner, inner.length - 1);
return ret;
}

Datei anzeigen

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import net.minecraft.server.Chunk;
import net.minecraft.server.MinecraftServer;
import static org.bukkit.craftbukkit.util.Java15Compat.Arrays_copyOf;
public class LongHashtable<V> extends LongHash
{
@ -55,7 +56,7 @@ public class LongHashtable<V> extends LongHash
return;
}
}
outer[outerIdx] = inner = Arrays.copyOf(inner, i + i);
outer[outerIdx] = inner = Arrays_copyOf(inner, i + i);
inner[i] = new Entry(key, value);
}
}