Loading core/java/android/util/IntArray.java +7 −11 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package android.util; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import java.util.Arrays; import libcore.util.EmptyArray; import java.util.Arrays; /** * Implements a growing array of int primitives. * Loading Loading @@ -102,7 +104,7 @@ public class IntArray implements Cloneable { ensureCapacity(1); int rightSegment = mSize - index; mSize++; checkBounds(index); ArrayUtils.checkBounds(mSize, index); if (rightSegment != 0) { // Move by 1 all values from the right of 'index' Loading Loading @@ -175,7 +177,7 @@ public class IntArray implements Cloneable { * Returns the value at the specified position in this array. */ public int get(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); return mValues[index]; } Loading @@ -183,7 +185,7 @@ public class IntArray implements Cloneable { * Sets the value at the specified position in this array. */ public void set(int index, int value) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); mValues[index] = value; } Loading @@ -205,7 +207,7 @@ public class IntArray implements Cloneable { * Removes the value at the specified index from this array. */ public void remove(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1); mSize--; } Loading @@ -223,10 +225,4 @@ public class IntArray implements Cloneable { public int[] toArray() { return Arrays.copyOf(mValues, mSize); } private void checkBounds(int index) { if (index < 0 || mSize <= index) { throw new ArrayIndexOutOfBoundsException(mSize, index); } } } core/java/android/util/LongArray.java +7 −11 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package android.util; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import java.util.Arrays; import libcore.util.EmptyArray; import java.util.Arrays; /** * Implements a growing array of long primitives. * Loading Loading @@ -102,7 +104,7 @@ public class LongArray implements Cloneable { ensureCapacity(1); int rightSegment = mSize - index; mSize++; checkBounds(index); ArrayUtils.checkBounds(mSize, index); if (rightSegment != 0) { // Move by 1 all values from the right of 'index' Loading Loading @@ -162,7 +164,7 @@ public class LongArray implements Cloneable { * Returns the value at the specified position in this array. */ public long get(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); return mValues[index]; } Loading @@ -170,7 +172,7 @@ public class LongArray implements Cloneable { * Sets the value at the specified position in this array. */ public void set(int index, long value) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); mValues[index] = value; } Loading @@ -192,7 +194,7 @@ public class LongArray implements Cloneable { * Removes the value at the specified index from this array. */ public void remove(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1); mSize--; } Loading @@ -210,10 +212,4 @@ public class LongArray implements Cloneable { public long[] toArray() { return Arrays.copyOf(mValues, mSize); } private void checkBounds(int index) { if (index < 0 || mSize <= index) { throw new ArrayIndexOutOfBoundsException(mSize, index); } } } core/java/com/android/internal/util/ArrayUtils.java +13 −0 Original line number Diff line number Diff line Loading @@ -587,4 +587,17 @@ public class ArrayUtils { public static @NonNull String[] defeatNullable(@Nullable String[] val) { 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); } } } Loading
core/java/android/util/IntArray.java +7 −11 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package android.util; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import java.util.Arrays; import libcore.util.EmptyArray; import java.util.Arrays; /** * Implements a growing array of int primitives. * Loading Loading @@ -102,7 +104,7 @@ public class IntArray implements Cloneable { ensureCapacity(1); int rightSegment = mSize - index; mSize++; checkBounds(index); ArrayUtils.checkBounds(mSize, index); if (rightSegment != 0) { // Move by 1 all values from the right of 'index' Loading Loading @@ -175,7 +177,7 @@ public class IntArray implements Cloneable { * Returns the value at the specified position in this array. */ public int get(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); return mValues[index]; } Loading @@ -183,7 +185,7 @@ public class IntArray implements Cloneable { * Sets the value at the specified position in this array. */ public void set(int index, int value) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); mValues[index] = value; } Loading @@ -205,7 +207,7 @@ public class IntArray implements Cloneable { * Removes the value at the specified index from this array. */ public void remove(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1); mSize--; } Loading @@ -223,10 +225,4 @@ public class IntArray implements Cloneable { public int[] toArray() { return Arrays.copyOf(mValues, mSize); } private void checkBounds(int index) { if (index < 0 || mSize <= index) { throw new ArrayIndexOutOfBoundsException(mSize, index); } } }
core/java/android/util/LongArray.java +7 −11 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package android.util; import com.android.internal.util.ArrayUtils; import com.android.internal.util.Preconditions; import java.util.Arrays; import libcore.util.EmptyArray; import java.util.Arrays; /** * Implements a growing array of long primitives. * Loading Loading @@ -102,7 +104,7 @@ public class LongArray implements Cloneable { ensureCapacity(1); int rightSegment = mSize - index; mSize++; checkBounds(index); ArrayUtils.checkBounds(mSize, index); if (rightSegment != 0) { // Move by 1 all values from the right of 'index' Loading Loading @@ -162,7 +164,7 @@ public class LongArray implements Cloneable { * Returns the value at the specified position in this array. */ public long get(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); return mValues[index]; } Loading @@ -170,7 +172,7 @@ public class LongArray implements Cloneable { * Sets the value at the specified position in this array. */ public void set(int index, long value) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); mValues[index] = value; } Loading @@ -192,7 +194,7 @@ public class LongArray implements Cloneable { * Removes the value at the specified index from this array. */ public void remove(int index) { checkBounds(index); ArrayUtils.checkBounds(mSize, index); System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1); mSize--; } Loading @@ -210,10 +212,4 @@ public class LongArray implements Cloneable { public long[] toArray() { return Arrays.copyOf(mValues, mSize); } private void checkBounds(int index) { if (index < 0 || mSize <= index) { throw new ArrayIndexOutOfBoundsException(mSize, index); } } }
core/java/com/android/internal/util/ArrayUtils.java +13 −0 Original line number Diff line number Diff line Loading @@ -587,4 +587,17 @@ public class ArrayUtils { public static @NonNull String[] defeatNullable(@Nullable String[] val) { 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); } } }