resolve merge conflicts of 7980b19bc8 to stage-aosp-master
am: 3147288c3b
Change-Id: Ie04ef5cd3277271304c3564ee6e41d8c24dee74c
This commit is contained in:
@@ -18,9 +18,11 @@ package android.util;
|
|||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.internal.util.Preconditions;
|
import com.android.internal.util.Preconditions;
|
||||||
import java.util.Arrays;
|
|
||||||
import libcore.util.EmptyArray;
|
import libcore.util.EmptyArray;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements a growing array of int primitives.
|
* Implements a growing array of int primitives.
|
||||||
*
|
*
|
||||||
@@ -102,7 +104,7 @@ public class IntArray implements Cloneable {
|
|||||||
ensureCapacity(1);
|
ensureCapacity(1);
|
||||||
int rightSegment = mSize - index;
|
int rightSegment = mSize - index;
|
||||||
mSize++;
|
mSize++;
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
|
|
||||||
if (rightSegment != 0) {
|
if (rightSegment != 0) {
|
||||||
// Move by 1 all values from the right of 'index'
|
// Move by 1 all values from the right of 'index'
|
||||||
@@ -175,7 +177,7 @@ public class IntArray implements Cloneable {
|
|||||||
* Returns the value at the specified position in this array.
|
* Returns the value at the specified position in this array.
|
||||||
*/
|
*/
|
||||||
public int get(int index) {
|
public int get(int index) {
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
return mValues[index];
|
return mValues[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +185,7 @@ public class IntArray implements Cloneable {
|
|||||||
* Sets the value at the specified position in this array.
|
* Sets the value at the specified position in this array.
|
||||||
*/
|
*/
|
||||||
public void set(int index, int value) {
|
public void set(int index, int value) {
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
mValues[index] = value;
|
mValues[index] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +207,7 @@ public class IntArray implements Cloneable {
|
|||||||
* Removes the value at the specified index from this array.
|
* Removes the value at the specified index from this array.
|
||||||
*/
|
*/
|
||||||
public void remove(int index) {
|
public void remove(int index) {
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1);
|
System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1);
|
||||||
mSize--;
|
mSize--;
|
||||||
}
|
}
|
||||||
@@ -223,10 +225,4 @@ public class IntArray implements Cloneable {
|
|||||||
public int[] toArray() {
|
public int[] toArray() {
|
||||||
return Arrays.copyOf(mValues, mSize);
|
return Arrays.copyOf(mValues, mSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBounds(int index) {
|
|
||||||
if (index < 0 || mSize <= index) {
|
|
||||||
throw new ArrayIndexOutOfBoundsException(mSize, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class LongArray implements Cloneable {
|
|||||||
ensureCapacity(1);
|
ensureCapacity(1);
|
||||||
int rightSegment = mSize - index;
|
int rightSegment = mSize - index;
|
||||||
mSize++;
|
mSize++;
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
|
|
||||||
if (rightSegment != 0) {
|
if (rightSegment != 0) {
|
||||||
// Move by 1 all values from the right of 'index'
|
// Move by 1 all values from the right of 'index'
|
||||||
@@ -166,7 +166,7 @@ public class LongArray implements Cloneable {
|
|||||||
* Returns the value at the specified position in this array.
|
* Returns the value at the specified position in this array.
|
||||||
*/
|
*/
|
||||||
public long get(int index) {
|
public long get(int index) {
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
return mValues[index];
|
return mValues[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ public class LongArray implements Cloneable {
|
|||||||
* Sets the value at the specified position in this array.
|
* Sets the value at the specified position in this array.
|
||||||
*/
|
*/
|
||||||
public void set(int index, long value) {
|
public void set(int index, long value) {
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
mValues[index] = value;
|
mValues[index] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ public class LongArray implements Cloneable {
|
|||||||
* Removes the value at the specified index from this array.
|
* Removes the value at the specified index from this array.
|
||||||
*/
|
*/
|
||||||
public void remove(int index) {
|
public void remove(int index) {
|
||||||
checkBounds(index);
|
ArrayUtils.checkBounds(mSize, index);
|
||||||
System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1);
|
System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1);
|
||||||
mSize--;
|
mSize--;
|
||||||
}
|
}
|
||||||
@@ -215,12 +215,6 @@ public class LongArray implements Cloneable {
|
|||||||
return Arrays.copyOf(mValues, mSize);
|
return Arrays.copyOf(mValues, mSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBounds(int index) {
|
|
||||||
if (index < 0 || mSize <= index) {
|
|
||||||
throw new ArrayIndexOutOfBoundsException(mSize, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if each element of {@code a} equals corresponding element from {@code b}
|
* Test if each element of {@code a} equals corresponding element from {@code b}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -626,4 +626,17 @@ public class ArrayUtils {
|
|||||||
public static @NonNull String[] defeatNullable(@Nullable String[] val) {
|
public static @NonNull String[] defeatNullable(@Nullable String[] val) {
|
||||||
return (val != null) ? val : EmptyArray.STRING;
|
return (val != null) ? val : EmptyArray.STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws {@link ArrayIndexOutOfBoundsException} if the index is out of bounds.
|
||||||
|
*
|
||||||
|
* @param len length of the array. Must be non-negative
|
||||||
|
* @param index the index to check
|
||||||
|
* @throws ArrayIndexOutOfBoundsException if the {@code index} is out of bounds of the array
|
||||||
|
*/
|
||||||
|
public static void checkBounds(int len, int index) {
|
||||||
|
if (index < 0 || len <= index) {
|
||||||
|
throw new ArrayIndexOutOfBoundsException("length=" + len + "; index=" + index);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user