The indexOf(Object) and lastIndexOf(Object) were incorrectly
raising a NullPointerException if null were passed as the argument. This patch file fixes the behavior so that these methods will correctly find a null element. Submitted by: Paul Jack ( pjack at sfaf dot org ) git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130730 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f405dbaea6
commit
4ab1ffccbe
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CursorableLinkedList.java,v 1.8 2002/06/16 03:39:40 mas Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CursorableLinkedList.java,v 1.9 2002/06/21 03:26:15 mas Exp $
|
||||||
* $Revision: 1.8 $
|
* $Revision: 1.9 $
|
||||||
* $Date: 2002/06/16 03:39:40 $
|
* $Date: 2002/06/21 03:26:15 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
|
@ -92,7 +92,7 @@ import java.lang.UnsupportedOperationException; // stops a javadoc warning
|
||||||
*
|
*
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @author Rodney Waldhoff
|
* @author Rodney Waldhoff
|
||||||
* @version $Id: CursorableLinkedList.java,v 1.8 2002/06/16 03:39:40 mas Exp $
|
* @version $Id: CursorableLinkedList.java,v 1.9 2002/06/21 03:26:15 mas Exp $
|
||||||
* @see java.util.LinkedList
|
* @see java.util.LinkedList
|
||||||
*/
|
*/
|
||||||
public class CursorableLinkedList implements List, Serializable {
|
public class CursorableLinkedList implements List, Serializable {
|
||||||
|
@ -446,14 +446,25 @@ public class CursorableLinkedList implements List, Serializable {
|
||||||
*/
|
*/
|
||||||
public int indexOf(Object o) {
|
public int indexOf(Object o) {
|
||||||
int ndx = 0;
|
int ndx = 0;
|
||||||
|
|
||||||
|
// perform the null check outside of the loop to save checking every
|
||||||
|
// single time through the loop.
|
||||||
|
if (null == o) {
|
||||||
for(Listable elt = _head.next(), past = null; null != elt && past != _head.prev(); elt = (past = elt).next()) {
|
for(Listable elt = _head.next(), past = null; null != elt && past != _head.prev(); elt = (past = elt).next()) {
|
||||||
if(null == o && null == elt.value()) {
|
if (null == elt.value()) {
|
||||||
return ndx;
|
|
||||||
} else if(o.equals(elt.value())) {
|
|
||||||
return ndx;
|
return ndx;
|
||||||
}
|
}
|
||||||
ndx++;
|
ndx++;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
for(Listable elt = _head.next(), past = null; null != elt && past != _head.prev(); elt = (past = elt).next()) {
|
||||||
|
if (o.equals(elt.value())) {
|
||||||
|
return ndx;
|
||||||
|
}
|
||||||
|
ndx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,14 +497,24 @@ public class CursorableLinkedList implements List, Serializable {
|
||||||
*/
|
*/
|
||||||
public int lastIndexOf(Object o) {
|
public int lastIndexOf(Object o) {
|
||||||
int ndx = _size-1;
|
int ndx = _size-1;
|
||||||
|
|
||||||
|
// perform the null check outside of the loop to save checking every
|
||||||
|
// single time through the loop.
|
||||||
|
if (null == o) {
|
||||||
for(Listable elt = _head.prev(), past = null; null != elt && past != _head.next(); elt = (past = elt).prev()) {
|
for(Listable elt = _head.prev(), past = null; null != elt && past != _head.next(); elt = (past = elt).prev()) {
|
||||||
if(null == o && null == elt.value()) {
|
if (null == elt.value()) {
|
||||||
return ndx;
|
|
||||||
} else if(o.equals(elt.value())) {
|
|
||||||
return ndx;
|
return ndx;
|
||||||
}
|
}
|
||||||
ndx--;
|
ndx--;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for(Listable elt = _head.prev(), past = null; null != elt && past != _head.next(); elt = (past = elt).prev()) {
|
||||||
|
if (o.equals(elt.value())) {
|
||||||
|
return ndx;
|
||||||
|
}
|
||||||
|
ndx--;
|
||||||
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue