public class DestroyableList<E extends Destroyable> extends Object implements Iterable<E>
Destroyable
s. When an object is removed from the list or the list is
cleared, it is Destroyable.destroy()
ed.
Note that this is not a proper java.util.List
because that interface exposes a ton
of different ways to manipulate the list, all of which make it very hard to reason about when or
whether your destroyables are destroyed. This list supports addition, removal, iteration and
random access. That's about it.
Modifier and Type | Method and Description |
---|---|
E |
add(E elem)
Adds (non-null)
elem to the end of the list. |
E |
add(int index,
E elem)
Inserts (non-null)
elem into the list at index . |
void |
clear()
Removes and destroys all elements in this list.
|
static <E extends Destroyable> |
create()
Constructs an empty list with an initial capacity of eight.
|
static <E extends Destroyable> |
createWithCapacity(int initCap)
Constructs an empty list with the specified initial capacity.
|
E |
get(int index)
Returns the element at
index . |
boolean |
isEmpty()
Returns true if the list is empty, false if it contains elements.
|
Iterator<E> |
iterator() |
boolean |
remove(E elem)
Removes and destroys (non-null)
elem . |
E |
remove(int index)
Removes and destroys the element at
index . |
int |
size()
Returns the size of the list.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static <E extends Destroyable> DestroyableList<E> create()
public static <E extends Destroyable> DestroyableList<E> createWithCapacity(int initCap)
public int size()
public boolean isEmpty()
public E get(int index)
index
.public E add(E elem)
elem
to the end of the list.elem
for convenience.public E add(int index, E elem)
elem
into the list at index
.elem
for convenience.public E remove(int index)
index
.public boolean remove(E elem)
elem
.public void clear()
Copyright © 2015. All Rights Reserved.