use Arrays.copy or Arrays.copyOfRange where applicable
Arrays.copy is easier to use than System.arrayCopy.
This commit is contained in:
@@ -80,8 +80,7 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
* if the specified {@link IntList} is null
|
* if the specified {@link IntList} is null
|
||||||
*/
|
*/
|
||||||
public IntList(final IntList intList) {
|
public IntList(final IntList intList) {
|
||||||
data = new int[intList.getCapacity()];
|
data = Arrays.copyOf(intList.data, intList.size());
|
||||||
System.arraycopy(intList.data, 0, data, 0, intList.size());
|
|
||||||
size = intList.size();
|
size = intList.size();
|
||||||
sorted = intList.sorted;
|
sorted = intList.sorted;
|
||||||
}
|
}
|
||||||
@@ -436,9 +435,7 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
if (from + length > size) {
|
if (from + length > size) {
|
||||||
throw new IndexOutOfBoundsException("from: " + from + " length: " + length);
|
throw new IndexOutOfBoundsException("from: " + from + " length: " + length);
|
||||||
}
|
}
|
||||||
final int[] result = new int[length];
|
return Arrays.copyOfRange(data, from, from + length);
|
||||||
System.arraycopy(data, from, result, 0, length);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -511,9 +508,7 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
data = EMPTY_ARRAY;
|
data = EMPTY_ARRAY;
|
||||||
} else {
|
} else {
|
||||||
final int[] newData = new int[size];
|
data = Arrays.copyOf(data, size);
|
||||||
System.arraycopy(data, 0, newData, 0, size);
|
|
||||||
data = newData;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user