|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.python.core.AbstractArray
Abstract class that manages bulk structural and data operations on arrays, defering type-specific element-wise operations to the subclass. Subclasses supply the underlying array and the type-specific operations--greatly reducing the need for casting (thus achieving array-like performances with collection-like flexibility). Also includes functionality to support integration with the the jdk's collections (via methods that return a modification increment).
Subclasses will want to provide the following methods (which are not declared in this class since subclasses should specify the explicit return type):
<type> get(int)
void set(int, <type>)
void add(<type>)
void add(int, <type>)
<type>[] toArray()
Clone cannot be supported since the array is not held locally. But the @link #AbstractArray(AbstractArray) constructor can be used for suclasses that need to support clone.
This "type-specific collections" approach was originally developed by Dennis Sosnoski, who provides a more complete library at the referenced URL. Sosnoski's library does not integrate with the jdk collection classes but provides collection-like classes.
Constructor Summary | |
AbstractArray(AbstractArray toCopy)
Since AbstractArray can support a clone method, this facilitates sublcasses that want to implement clone (poor man's cloning). |
|
AbstractArray(java.lang.Class type)
Creates the managed array with a default size of 10. |
|
AbstractArray(java.lang.Class type,
int size)
Creates the managed array with the specified size. |
|
AbstractArray(java.lang.Class type,
int[] dimensions)
Construtor for multi-dimensional array types. |
|
AbstractArray(int size)
Use when the subclass has a preexisting array. |
Method Summary | |
void |
appendArray(java.lang.Object ofArrayType)
Appends the supplied array, which must be an array of the same type as this , to the end of this .
|
void |
clear()
Set the array to the empty state, clearing all the data out and nulling objects (or "zero-ing" primitives). |
java.lang.Object |
copyArray()
Constructs and returns a simple array containing the same data as held in this growable array. |
int |
getModCountIncr()
Returns the modification count increment, which is used by AbstractList subclasses to adjust modCount
AbstractList uses it's modCount field
to invalidate concurrent operations (like iteration) that should
fail if the underlying array changes structurally during the
operation. |
int |
getSize()
Get the number of values currently present in the array. |
void |
remove(int index)
Remove a value from the array. |
void |
remove(int start,
int stop)
Removes a range from the array at the specified indices. |
void |
replaceSubArray(int thisStart,
int thisStop,
java.lang.Object srcArray,
int srcStart,
int srcStop)
Replace a range of this array with another subarray. |
void |
replaceSubArray(java.lang.Object array,
int atIndex)
Allows an array type to overwrite a segment of the array. |
void |
setSize(int count)
Sets the number of values currently present in the array. |
java.lang.String |
toString()
Provides a default comma-delimited representation of array. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public AbstractArray(AbstractArray toCopy)
public MyManagedArray(MyManagedArray toCopy) { super(this); this.baseArray = ()toCopy.copyArray(); this.someProp = toCopy.someProp; } public Object clone() { return new MyManagedArray(this); }
toCopy
- public AbstractArray(int size)
size
- the initial size of the arraypublic AbstractArray(java.lang.Class type)
type
- array element type (primitive type or object class)public AbstractArray(java.lang.Class type, int[] dimensions)
char[][]
. This class only manages the
top level dimension of the array. For single dimension
arrays (the more typical usage), use the other constructors.
type
- Array element type (primitive type or object class).dimensions
- An int array specifying the dimensions. For
a 2D array, something like new int[] {10,0}
to
create 10 elements each of which can hold an reference to an
array of the same type.Array.newInstance(java.lang.Class, int[])
public AbstractArray(java.lang.Class type, int size)
type
- array element type (primitive type or object class)size
- number of elements initially allowed in arrayMethod Detail |
public void appendArray(java.lang.Object ofArrayType)
this
, to the end of this
.
AbstractList
subclasses should update their
modCount
after calling this method.
ofArrayType
- the array to appendpublic void clear()
Note: This method does not set modCountIncr
to
1
even though java.util.ArrayList
would.
AbstractList
subclasses should update their
modCount
after calling this method.
public java.lang.Object copyArray()
public void remove(int index)
AbstractList
subclasses should always increment
their modCount
method after calling this, as
remove
always causes a structural modification.
index
- index number of value to be removedpublic void remove(int start, int stop)
start
- inclusivestop
- exclusivepublic void replaceSubArray(java.lang.Object array, int atIndex)
(atIndex + 1) + ofArrayType
's length
is greater than the current length.
AbstractList
subclasses should update their
modCount
after calling this method.
array
- atIndex
- public void replaceSubArray(int thisStart, int thisStop, java.lang.Object srcArray, int srcStart, int srcStop)
thisStart
- the start index (inclusive) of the subarray in this
array to be replacedthisStop
- the stop index (exclusive) of the subarray in this
array to be replacedsrcArray
- the source array from which to copysrcStart
- the start index (inclusive) of the replacement subarraysrcStop
- the stop index (exclusive) of the replacement subarraypublic void setSize(int count)
AbstractList
subclasses should update their
modCount
after calling this method.
count
- number of values to be setpublic int getSize()
public java.lang.String toString()
Object.toString()
public int getModCountIncr()
AbstractList
subclasses to adjust modCount
AbstractList
uses it's modCount
field
to invalidate concurrent operations (like iteration) that should
fail if the underlying array changes structurally during the
operation.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |