java.lang.StringBuilder
, but for arrays of integers.
There is an abstract base for arrays to which a client appends,
and one for arrays to which the client prepends new values.
The particular virtue of these classes is that, if the ultimate
size of the built array may be known in advance, then the result
may be returned without a copy, using take()
.
Modifier and Type | Class and Description |
---|---|
public abstract static class | AbstractIntArrayBuilder.Forward
Abstract base of integer array builders that append to their content, building the result left to right. |
public abstract static class | AbstractIntArrayBuilder.Reverse
Abstract base of integer array builders that prepend to their content, building the result right to left. |
Modifier and Type | Field and Description |
---|---|
protected static final int[] | EMPTY_INT_ARRAY
An empty array of int for builder initial state, etc.. |
protected static final int | MINSIZE
Number of elements by default. |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
protected abstract void | |
public abstract int | |
public abstract int | |
public abstract Object | Returns: the contents as a Pythonstr Provide the contents as an array and reset the builder to empty. |
public String | toString()
Overrides java. String (non-destructively,
but inefficiently).
|
protected abstract int[] | Returns: the elements in the bufferAn array of the elements in the buffer (not modified by methods on this object hereafter). |
EMPTY_INT_ARRAY | back to summary |
---|---|
protected static final int[] EMPTY_INT_ARRAY An empty array of int for builder initial state, etc.. |
MINSIZE | back to summary |
---|---|
protected static final int MINSIZE Number of elements by default. |
AbstractIntArrayBuilder | back to summary |
---|---|
public AbstractIntArrayBuilder() |
ensure | back to summary |
---|---|
protected abstract void ensure(int n) Ensure there is room for another
|
length | back to summary |
---|---|
public abstract int length() The number of elements currently
|
max | back to summary |
---|---|
public abstract int max() The maximum value stored. Implementation Note The motivation for this is to know the range of code point values when representing a string. An over-estimate would be ok.)
|
take | back to summary |
---|---|
public abstract Object take() Provide the contents as an array and reset the builder to empty.
(This is a "destructive read".) The return type is Object in
order that sub-classes may define the specific type (for example,
Implementation Note In many implementations, if the client has chosen an
initial capacity exactly matching
|
toString | back to summary |
---|---|
public String toString() Overrides java. Provide the contents as a Java
|
value | back to summary |
---|---|
protected abstract int[] value() An array of the elements in the buffer (not modified by methods on this object hereafter).
|
appendUnchecked(int)
.
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public AbstractIntArrayBuilder. | |
public AbstractIntArrayBuilder. | Returns: this builderfrom which to take items seqAppend all the elements from a sequence. |
public AbstractIntArrayBuilder. | |
protected abstract void |
Forward | back to summary |
---|---|
public Forward() |
append | back to summary |
---|---|
public AbstractIntArrayBuilder. Append one element.
|
append | back to summary |
---|---|
public AbstractIntArrayBuilder. Append all the elements from a sequence.
|
append | back to summary |
---|---|
public AbstractIntArrayBuilder. Append all the elements available from an iterator.
|
appendUnchecked | back to summary |
---|---|
protected abstract void appendUnchecked(int v) Append one element without ensuring that there is space. This
method is for use when it is known that there is space for the
element, for example, inside a loop before which when
|
prependUnchecked(int)
.
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public AbstractIntArrayBuilder. | |
public AbstractIntArrayBuilder. | Returns: this builderfrom which to take items seqPrepend all the elements from a sequence. |
public AbstractIntArrayBuilder. | Returns: this builderfrom which to take items iter)Prepend all the elements available from an iterator, working
backwards with |
protected abstract void |
Reverse | back to summary |
---|---|
public Reverse() |
prepend | back to summary |
---|---|
public AbstractIntArrayBuilder. Prepend one element.
|
prepend | back to summary |
---|---|
public AbstractIntArrayBuilder. Prepend all the elements from a sequence. The sequence is not
reversed by this: it is prepended the right way around. After the
call
|
prepend | back to summary |
---|---|
public AbstractIntArrayBuilder. Prepend all the elements available from an iterator, working
backwards with
|
prependUnchecked | back to summary |
---|---|
protected abstract void prependUnchecked(int v) Prepend one element without ensuring that there is space. This
method is for use when it is known that there is space for the
element, for example, inside a loop before which when
|