Top Description Inners Fields Constructors Methods
org.python.core.stringlib

public abstract Class AbstractIntArrayBuilder

extends Object
Class Inheritance
Known Direct Subclasses
org.python.core.stringlib.AbstractIntArrayBuilder.Forward, org.python.core.stringlib.AbstractIntArrayBuilder.Reverse
Imports
java.util.Iterator, .ListIterator, org.python.core.PySequence

The base of two classes that that provide elastic buffers of integer values, somewhat like the 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().

Nested and Inner Type Summary

Modifier and TypeClass 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.

Field Summary

Modifier and TypeField 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.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected abstract void
ensure(int
to make additional space for
n
)

Ensure there is room for another n elements.

public abstract int

Returns:

the number of elements currently.
length
()

The number of elements currently

public abstract int

Returns:

The maximum int stored.
max
()

The maximum value stored.

public abstract Object

Returns:

the contents as a Python str
take
()

Provide the contents as an array and reset the builder to empty.

public String
toString()

Overrides java.lang.Object.toString.

Provide the contents as a Java String (non-destructively, but inefficiently).
protected abstract int[]

Returns:

the elements in the buffer
value
()

An array of the elements in the buffer (not modified by methods on this object hereafter).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

EMPTY_INT_ARRAYback to summary
protected static final int[] EMPTY_INT_ARRAY

An empty array of int for builder initial state, etc..

MINSIZEback to summary
protected static final int MINSIZE

Number of elements by default.

Constructor Detail

AbstractIntArrayBuilderback to summary
public AbstractIntArrayBuilder()

Method Detail

ensureback to summary
protected abstract void ensure(int n)

Ensure there is room for another n elements. In general, this will mean allocating new storage (of a carefully-chosen size ≥ n+length()) and copying the existing contents to it.

Parameters
n:int

to make additional space for

lengthback to summary
public abstract int length()

The number of elements currently

Returns:int

the number of elements currently.

maxback 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.)

Returns:int

The maximum int stored.

takeback 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, int[] or byte[]).

Implementation Note

In many implementations, if the client has chosen an initial capacity exactly matching length() at the time this method is called, then the result may be returned without a copy. (This must be the last remaining reference to the array originally allocated: it must be impossible for the the builder to re-use it.) Otherwise, returning a new array is inevitable.

Returns:Object

the contents as a Python str

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Provide the contents as a Java String (non-destructively, but inefficiently).

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
valueback to summary
protected abstract int[] value()

An array of the elements in the buffer (not modified by methods on this object hereafter).

Returns:int[]

the elements in the buffer

org.python.core.stringlib back to summary

public abstract Class AbstractIntArrayBuilder.Forward

extends AbstractIntArrayBuilder
Class Inheritance
Known Direct Subclasses
org.python.core.stringlib.ByteArrayBuilder, org.python.core.stringlib.IntArrayBuilder

Abstract base of integer array builders that append to their content, building the result left to right. Implementations need only define appendUnchecked(int).

Field Summary

Inherited from org.python.core.stringlib.AbstractIntArrayBuilder:
EMPTY_INT_ARRAYMINSIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public AbstractIntArrayBuilder.Forward

Returns:

this builder
append
(int
to append
v
)

Append one element.

public AbstractIntArrayBuilder.Forward

Returns:

this builder
append
(PySequence.OfInt
from which to take items
seq
)

Append all the elements from a sequence.

public AbstractIntArrayBuilder.Forward

Returns:

this builder
append
(Iterator<Integer>
from which to take items
iter
)

Append all the elements available from an iterator.

protected abstract void
appendUnchecked(int
to append
v
)

Append one element without ensuring that there is space.

Inherited from org.python.core.stringlib.AbstractIntArrayBuilder:
ensurelengthmaxtaketoStringvalue

Constructor Detail

Forwardback to summary
public Forward()

Method Detail

appendback to summary
public AbstractIntArrayBuilder.Forward append(int v)

Append one element.

Parameters
v:int

to append

Returns:AbstractIntArrayBuilder.Forward

this builder

appendback to summary
public AbstractIntArrayBuilder.Forward append(PySequence.OfInt seq)

Append all the elements from a sequence.

Parameters
seq:PySequence.OfInt

from which to take items

Returns:AbstractIntArrayBuilder.Forward

this builder

appendback to summary
public AbstractIntArrayBuilder.Forward append(Iterator<Integer> iter)

Append all the elements available from an iterator.

Parameters
iter:Iterator<Integer>

from which to take items

Returns:AbstractIntArrayBuilder.Forward

this builder

appendUncheckedback 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 ensure(int) has been called.

Parameters
v:int

to append

org.python.core.stringlib back to summary

public abstract Class AbstractIntArrayBuilder.Reverse

extends AbstractIntArrayBuilder
Class Inheritance
Known Direct Subclasses
org.python.core.stringlib.IntArrayReverseBuilder

Abstract base of integer array builders that prepend to their content, building the result right to left. Implementations need only define prependUnchecked(int).

Field Summary

Inherited from org.python.core.stringlib.AbstractIntArrayBuilder:
EMPTY_INT_ARRAYMINSIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public AbstractIntArrayBuilder.Reverse

Returns:

this builder
prepend
(int
to prepend
v
)

Prepend one element.

public AbstractIntArrayBuilder.Reverse

Returns:

this builder
prepend
(PySequence.OfInt
from which to take items
seq
)

Prepend all the elements from a sequence.

public AbstractIntArrayBuilder.Reverse

Returns:

this builder
prepend
(ListIterator<Integer>
from which to take items
iter
)

Prepend all the elements available from an iterator, working backwards with iter.previous().

protected abstract void
prependUnchecked(int
to prepend
v
)

Prepend one element without ensuring that there is space.

Inherited from org.python.core.stringlib.AbstractIntArrayBuilder:
ensurelengthmaxtaketoStringvalue

Constructor Detail

Reverseback to summary
public Reverse()

Method Detail

prependback to summary
public AbstractIntArrayBuilder.Reverse prepend(int v)

Prepend one element.

Parameters
v:int

to prepend

Returns:AbstractIntArrayBuilder.Reverse

this builder

prependback to summary
public AbstractIntArrayBuilder.Reverse prepend(PySequence.OfInt seq)

Prepend all the elements from a sequence. The sequence is not reversed by this: it is prepended the right way around. After the call seq[0] is first in the buffer.

Parameters
seq:PySequence.OfInt

from which to take items

Returns:AbstractIntArrayBuilder.Reverse

this builder

prependback to summary
public AbstractIntArrayBuilder.Reverse prepend(ListIterator<Integer> iter)

Prepend all the elements available from an iterator, working backwards with iter.previous().

Parameters
iter:ListIterator<Integer>

from which to take items

Returns:AbstractIntArrayBuilder.Reverse

this builder

prependUncheckedback 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 ensure(int) has been called.

Parameters
v:int

to prepend