Do our null checking less wonkily.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2959 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user