null out 'next'
This commit is contained in:
parent
08d5a0c86a
commit
d7034e9eae
@ -14,7 +14,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.oscim.utils.pool;
|
package org.oscim.utils.pool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for making poolable objects.
|
||||||
|
* Instead of using an additional list to hold pool items just extend this class.
|
||||||
|
*
|
||||||
|
* Also handy for objects that exist in only *one list* at a time.
|
||||||
|
* */
|
||||||
|
|
||||||
public class Inlist<T extends Inlist<T>> {
|
public class Inlist<T extends Inlist<T>> {
|
||||||
|
|
||||||
@ -31,12 +36,15 @@ public class Inlist<T extends Inlist<T>> {
|
|||||||
|
|
||||||
public static <T extends Inlist<T>> T remove(T list, T item) {
|
public static <T extends Inlist<T>> T remove(T list, T item) {
|
||||||
if (item == list) {
|
if (item == list) {
|
||||||
return item.next;
|
T head = item.next;
|
||||||
|
item.next = null;
|
||||||
|
return head;
|
||||||
}
|
}
|
||||||
for (Inlist<T> prev = list, it = list.next; it != null; it = it.next) {
|
for (Inlist<T> prev = list, it = list.next; it != null; it = it.next) {
|
||||||
|
|
||||||
if (it == item) {
|
if (it == item) {
|
||||||
prev.next = it.next;
|
prev.next = item.next;
|
||||||
|
item.next = null;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
prev = it;
|
prev = it;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user