Add null analysis annotation to CollectionUtils

Change-Id: I3a610b037d6d1431cced3ea193171108bd5a040d
This commit is contained in:
Tadashi G. Takaoka 2014-10-27 18:20:44 +09:00
parent 5547b49b17
commit 7a3de4dca9
2 changed files with 7 additions and 6 deletions

View file

@ -19,15 +19,17 @@ package com.android.inputmethod.latin.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class CollectionUtils { public final class CollectionUtils {
private CollectionUtils() { private CollectionUtils() {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
} }
public static <E> ArrayList<E> arrayAsList(final E[] array, final int start, final int end) { @Nonnull
if (array == null) { public static <E> ArrayList<E> arrayAsList(@Nonnull final E[] array, final int start,
throw new NullPointerException(); final int end) {
}
if (start < 0 || start > end || end > array.length) { if (start < 0 || start > end || end > array.length) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@ -44,7 +46,7 @@ public final class CollectionUtils {
* @param c Collection to test. * @param c Collection to test.
* @return Whether c contains no elements. * @return Whether c contains no elements.
*/ */
public static boolean isNullOrEmpty(final Collection<?> c) { public static boolean isNullOrEmpty(@Nullable final Collection<?> c) {
return c == null || c.isEmpty(); return c == null || c.isEmpty();
} }
} }

View file

@ -51,5 +51,4 @@ public class CollectionUtilsTests extends AndroidTestCase {
assertTrue(CollectionUtils.isNullOrEmpty(Collections.EMPTY_SET)); assertTrue(CollectionUtils.isNullOrEmpty(Collections.EMPTY_SET));
assertFalse(CollectionUtils.isNullOrEmpty(Collections.singleton("Not empty"))); assertFalse(CollectionUtils.isNullOrEmpty(Collections.singleton("Not empty")));
} }
} }