public class PartitionedArray<E>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
idx
The top of the stack (MUST be a
non-null value). |
private static int |
INCREMENT
Number of elements by which to grow or shrink the array.
|
private DynamicArray<E>[] |
partitions
The stack of our partitions.
|
private int |
size
The total number of elements in the array.
|
Constructor and Description |
---|
PartitionedArray()
Default constructor.
|
PartitionedArray(PartitionedArray src)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(boolean global,
E val)
Add the object to the end of the array.
|
void |
add(E val)
Add the object to the end of the array.
|
void |
addAll(java.util.Collection<? extends E> val)
Add the objects to the end of the array in the proper order.
|
void |
clear()
Remove all elements and reset state.
|
boolean |
contains(E val)
Report if the given instance exists in the array.
|
void |
markPartition()
Mark the current end of the array as a new partition.
|
boolean |
partitionContains(int index,
E val,
boolean forward)
Report if the given instance exists in a specific partition within the array.
|
void |
remove(E val)
Remove the first instance of the given object in the array.
|
void |
remove(E val,
boolean all)
Remove the first instance or all instances of the given object in the
array.
|
void |
removePartition()
Remove all elements contained in the last partition of the array and
remove the partition definition too.
|
int |
size()
Gets the current number of elements in the array.
|
E[] |
toArray(E[] e)
Obtain access to a copy of the array.
|
private static final int INCREMENT
private DynamicArray<E>[] partitions
private int idx
non-null
value).private int size
public PartitionedArray()
public PartitionedArray(PartitionedArray src)
public void add(E val)
val
- The instance to add to the list.public void add(boolean global, E val)
global
- true
if the element should be added to the
global partition. Otherwise the element will be added to
the current partition.val
- The instance to add to the list.public void addAll(java.util.Collection<? extends E> val)
val
- The collection of elements to add to the list.public void clear()
public boolean contains(E val)
val
- The instance to search for in the list.true
if there is at least one copy of this
object instance in the array.public boolean partitionContains(int index, E val, boolean forward)
index
- Zero-based index of the target partition in the array of partitions.val
- The instance to search for in the list.forward
- true
to search the partition from front to back; false
to search
from back to front.true
if there is at least one copy of this object instance in the
specified partition.public int size()
public E[] toArray(E[] e)
public void markPartition()
removePartition()
will be "contained" in this partition. This
is similar to a push on a stack, except thatpublic void removePartition()
markPartition()
.public void remove(E val)
val
- The instance to remove from the list.public void remove(E val, boolean all)
val
- The instance to remove from the list.all
- true
to remove all found instances, otherwise
only remove the first instance found.