Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 02:50:05 +01:00
Make custom toArray methods fulfill the method contract (#2089)
* Make PropertyKeySet#toArray(T) fulfill the method contract * Make LocalBlockVectorSet#toArray(T) fulfill the method contract
Dieser Commit ist enthalten in:
Ursprung
a63037b92d
Commit
90baa790c3
@ -6,6 +6,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.zaxxer.sparsebits.SparseBitSet;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
@ -235,12 +236,15 @@ public class LocalBlockVectorSet implements BlockVector3Set {
|
||||
return toArray((Object[]) null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T[] toArray(T[] array) {
|
||||
int size = size();
|
||||
if (array == null || array.length < size) {
|
||||
array = (T[]) new BlockVector3[size];
|
||||
if (array.length < size) {
|
||||
array = Arrays.copyOf(array, size);
|
||||
} else if (array.length > size) {
|
||||
array[size] = null; // mark as end to comply with the method contract
|
||||
}
|
||||
int index = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -73,7 +73,16 @@ public class PropertyKeySet implements Set<PropertyKey> {
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T[] toArray(@Nonnull T[] a) {
|
||||
T[] array = Arrays.copyOf(a, this.bits.cardinality());
|
||||
T[] array;
|
||||
final int cardinality = this.bits.cardinality();
|
||||
if (cardinality > a.length) {
|
||||
array = Arrays.copyOf(a, cardinality);
|
||||
} else {
|
||||
array = a;
|
||||
if (a.length > cardinality) {
|
||||
array[cardinality] = null; // mark as end to comply with the method contract
|
||||
}
|
||||
}
|
||||
Iterator<PropertyKey> iter = iterator();
|
||||
for (int i = 0; i < array.length && iter.hasNext(); i++) {
|
||||
array[i] = (T) iter.next();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren