use Arrays.copy or Arrays.copyOfRange where applicable

Arrays.copy is easier to use than System.arrayCopy.
This commit is contained in:
2017-12-03 09:26:52 +01:00
parent ef5d7817b2
commit ba51b62a53

View File

@@ -80,8 +80,7 @@ public final class IntList implements Serializable, Cloneable {
* if the specified {@link IntList} is null
*/
public IntList(final IntList intList) {
data = new int[intList.getCapacity()];
System.arraycopy(intList.data, 0, data, 0, intList.size());
data = Arrays.copyOf(intList.data, intList.size());
size = intList.size();
sorted = intList.sorted;
}
@@ -436,9 +435,7 @@ public final class IntList implements Serializable, Cloneable {
if (from + length > size) {
throw new IndexOutOfBoundsException("from: " + from + " length: " + length);
}
final int[] result = new int[length];
System.arraycopy(data, from, result, 0, length);
return result;
return Arrays.copyOfRange(data, from, from + length);
}
/**
@@ -511,9 +508,7 @@ public final class IntList implements Serializable, Cloneable {
if (size == 0) {
data = EMPTY_ARRAY;
} else {
final int[] newData = new int[size];
System.arraycopy(data, 0, newData, 0, size);
data = newData;
data = Arrays.copyOf(data, size);
}
}