|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.partnersoft.data.DynamicArray
com.partnersoft.data.AbstractDynamicArray<T>
public abstract class AbstractDynamicArray<T>
A DynamicArray of Objects.
It would be nice to make this fully parameterizable via Generics, but it doesn't seem to be possible due to the limitations on instantiation of generic types and array handling.
It would be nice to use reflection to take care of the newArray() method, too, but I've found (around v1.5) that it takes three times as long to use Array.newInstance(type, size) than to use new Foo[size]. newArray() gets called a lot, especially during early growth, so that seems bad.
So, a compromise approach. Either generate an inline class like this:
AbstractDynamicObjectArray<Foo> array = new AbstractDynamicArray<Foo>() {
protected Foo[] newArrayImp(size) {
return new Foo[size];
}
};
Or, a full class like this:
public class DynamicFooArray extends AbstractDynamicArray<Foo> {
public DynamicFooArray() {
}
public DynamicFooArray(int capacity) {
super(capacity);
}
public DynamicFooArray(Foo...contents) {
super(contents);
}
protected Foo[] newArrayImp(size) {
return new Foo[size];
}
Copyright 2001-2006 Partner Software, Inc.
| Field Summary | |
|---|---|
T[] |
array
|
| Fields inherited from class com.partnersoft.data.DynamicArray |
|---|
arrayObject, capacity, end, fastGrowthFactor, fastGrowthLimit, slowGrowthAmount, start |
| Constructor Summary | |
|---|---|
AbstractDynamicArray()
Creates an empty DynamicObjectArray, for objects of the given type, with size and capacity of 0. |
|
AbstractDynamicArray(int capacity)
Creates a DynamicObjectArray of the given type and given capacity. |
|
AbstractDynamicArray(T... contents)
Creates a DynamicObjectArray of the given type and initial contents. |
|
| Method Summary | |
|---|---|
void |
add(T value)
Append a single object to the array. |
void |
addMultiple(T value,
int copyCount)
Append a single object multiple times. |
void |
append(java.util.Collection<T> values)
Append a collection of objects to the array. |
void |
append(T... values)
Append an array of objects to the array. |
java.lang.String |
contentsToString()
Returns the contents as a String. |
void |
fitToSize(int newSize,
T defaultValue)
Sets the array to the given size by either truncating or filling with the given defaultValue. |
java.util.Iterator<T> |
iterator()
|
void |
newArray(int size)
Allocates a new, empty array of the given size and assign it to the arrayObject property. |
protected abstract T[] |
newArrayImp(int size)
Subclasses must implement this to return an array of the correct type and size. |
T[] |
toFixedArray()
|
java.util.List<T> |
toList()
|
| Methods inherited from class com.partnersoft.data.DynamicArray |
|---|
append, clear, copy, copy, copyExactly, copyFrom, copyTo, insert, isEmpty, makeRoomFor, makeRoomFor, pack, remove, size, subsection, tidy, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public T[] array
| Constructor Detail |
|---|
public AbstractDynamicArray()
public AbstractDynamicArray(int capacity)
public AbstractDynamicArray(T... contents)
| Method Detail |
|---|
protected abstract T[] newArrayImp(int size)
public void add(T value)
public void addMultiple(T value,
int copyCount)
public void append(T... values)
public void append(java.util.Collection<T> values)
public void fitToSize(int newSize,
T defaultValue)
newSize - defaultValue - public java.lang.String contentsToString()
public final T[] toFixedArray()
public java.util.List<T> toList()
public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public void newArray(int size)
DynamicArray
public abstract void newArray(int size) {
arrayObject = array = new Foo[size];
}
newArray in class DynamicArray
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||