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)
|
public static Object[] add (Object[] list, int startIdx, Object element)
|
||||||
{
|
{
|
||||||
if (element == null) {
|
requireNotNull(element);
|
||||||
throw NPE();
|
|
||||||
}
|
|
||||||
// make sure we've got a list to work with
|
// make sure we've got a list to work with
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new Object[DEFAULT_LIST_SIZE];
|
list = new Object[DEFAULT_LIST_SIZE];
|
||||||
@@ -147,9 +146,8 @@ public class ListUtil
|
|||||||
*/
|
*/
|
||||||
public static Object[] insert (Object[] list, int index, Object element)
|
public static Object[] insert (Object[] list, int index, Object element)
|
||||||
{
|
{
|
||||||
if (element == null) {
|
requireNotNull(element);
|
||||||
throw NPE();
|
|
||||||
}
|
|
||||||
// make sure we've got a list to work with
|
// make sure we've got a list to work with
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new Object[DEFAULT_LIST_SIZE];
|
list = new Object[DEFAULT_LIST_SIZE];
|
||||||
@@ -215,9 +213,8 @@ public class ListUtil
|
|||||||
protected static Object[] testAndAdd (
|
protected static Object[] testAndAdd (
|
||||||
EqualityComparator eqc, Object[] list, Object element)
|
EqualityComparator eqc, Object[] list, Object element)
|
||||||
{
|
{
|
||||||
if (element == null) {
|
requireNotNull(element == null);
|
||||||
throw NPE();
|
|
||||||
}
|
|
||||||
// make sure we've got a list to work with
|
// make sure we've got a list to work with
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new Object[DEFAULT_LIST_SIZE];
|
list = new Object[DEFAULT_LIST_SIZE];
|
||||||
@@ -327,9 +324,7 @@ public class ListUtil
|
|||||||
protected static int indexOf (
|
protected static int indexOf (
|
||||||
EqualityComparator eqc, Object[] list, Object element)
|
EqualityComparator eqc, Object[] list, Object element)
|
||||||
{
|
{
|
||||||
if (element == null) {
|
requireNotNull(element == null);
|
||||||
throw NPE();
|
|
||||||
}
|
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
for (int ii = 0, nn = list.length; ii < nn; ii++) {
|
for (int ii = 0, nn = list.length; ii < nn; ii++) {
|
||||||
if (eqc.equals(list[ii], element)) {
|
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(
|
if (element == null) {
|
||||||
"ListUtil does not support null elements.");
|
throw new NullPointerException("ListUtil does not support null elements.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user