From d443146c343fd880eb6178bae94edec0865bce62 Mon Sep 17 00:00:00 2001 From: David Faden Date: Tue, 28 Oct 2014 14:22:09 -0700 Subject: Add documentation for CollectionUtils#arrayAsList (This is a cherrypick of http://ag/576739) Also, modify the IllegalArgumentException to capture the values passed for start, end, and array.length to make debugging easier in the unlikely event that it is thrown. Add corresponding tests for the exceptions. Tested: tapas LatinImeGoogle LatinImeGoogleTests userdebug make -j30 && \ adb install -r \ out/target/product/generic/data/app/LatinImeGoogleTests/LatinImeGoogleTests.apk && \ adb install -r \ out/target/product/generic/system/app/LatinImeGoogle/LatinImeGoogle.apk && \ adb shell am instrument -w -e class \ com.android.inputmethod.latin.utils.CollectionUtilsTests \ com.google.android.inputmethod.latin.tests/android.support.test.runner.AndroidJUnitRunner Change-Id: I0c579ca4f4f2a9b2575aa6f8fa75e3ee4a21cf8a --- .../android/inputmethod/latin/utils/CollectionUtils.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod/latin/utils/CollectionUtils.java') diff --git a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java index f9839eb91..01f5e1079 100644 --- a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java @@ -22,16 +22,27 @@ import java.util.Collection; import javax.annotation.Nonnull; import javax.annotation.Nullable; +/** + * Utility methods for working with collections. + */ public final class CollectionUtils { private CollectionUtils() { // This utility class is not publicly instantiable. } + /** + * Converts a sub-range of the given array to an ArrayList of the appropriate type. + * @param array Array to be converted. + * @param start First index inclusive to be converted. + * @param end Last index exclusive to be converted. + * @throws IllegalArgumentException if start or end are out of range or start > end. + */ @Nonnull public static ArrayList arrayAsList(@Nonnull final E[] array, final int start, final int end) { if (start < 0 || start > end || end > array.length) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Invalid start: " + start + " end: " + end + + " with array.length: " + array.length); } final ArrayList list = new ArrayList<>(end - start); -- cgit v1.2.3-83-g751a