diff --git a/src/main/java/com/samskivert/util/ListUtil.java b/src/main/java/com/samskivert/util/ListUtil.java index 36b6b9e2..69d283e0 100644 --- a/src/main/java/com/samskivert/util/ListUtil.java +++ b/src/main/java/com/samskivert/util/ListUtil.java @@ -103,9 +103,8 @@ public class ListUtil */ public static Object[] add (Object[] list, int startIdx, Object element) { - if (element == null) { - throw NPE(); - } + requireNotNull(element); + // make sure we've got a list to work with if (list == null) { list = new Object[DEFAULT_LIST_SIZE]; @@ -147,9 +146,8 @@ public class ListUtil */ public static Object[] insert (Object[] list, int index, Object element) { - if (element == null) { - throw NPE(); - } + requireNotNull(element); + // make sure we've got a list to work with if (list == null) { list = new Object[DEFAULT_LIST_SIZE]; @@ -215,9 +213,8 @@ public class ListUtil protected static Object[] testAndAdd ( EqualityComparator eqc, Object[] list, Object element) { - if (element == null) { - throw NPE(); - } + requireNotNull(element == null); + // make sure we've got a list to work with if (list == null) { list = new Object[DEFAULT_LIST_SIZE]; @@ -327,9 +324,7 @@ public class ListUtil protected static int indexOf ( EqualityComparator eqc, Object[] list, Object element) { - if (element == null) { - throw NPE(); - } + requireNotNull(element == null); if (list != null) { for (int ii = 0, nn = list.length; ii < nn; ii++) { if (eqc.equals(list[ii], element)) { @@ -489,12 +484,13 @@ public class ListUtil } /** - * Throw a NullPointerException with the bad news. + * Throws a NullPointerException if the element is null. */ - protected static NullPointerException NPE () + protected static void requireNotNull (Object element) { - return new NullPointerException( - "ListUtil does not support null elements."); + if (element == null) { + throw new NullPointerException("ListUtil does not support null elements."); + } } /**