Package org.aesh.terminal.utils
Class IntArrayBuilder
java.lang.Object
org.aesh.terminal.utils.IntArrayBuilder
A dynamically resizable int array builder similar to StringBuilder.
- Author:
- Ståle W. Pedersen
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty IntArrayBuilder with default initial capacity.IntArrayBuilder(int size) Create an empty IntArrayBuilder with the specified initial capacity.IntArrayBuilder(int[] ints) Create an IntArrayBuilder initialized with a copy of the given array. -
Method Summary
Modifier and TypeMethodDescriptionappend(int c) Append a single integer to this builder.append(int[] str) Append an array of integers to this builder.voidRemove the last entry from this builder.intsize()Return the number of integers currently in this builder.int[]toArray()Return the contents of this builder as a new int array.
-
Constructor Details
-
IntArrayBuilder
public IntArrayBuilder()Create an empty IntArrayBuilder with default initial capacity. -
IntArrayBuilder
public IntArrayBuilder(int size) Create an empty IntArrayBuilder with the specified initial capacity.- Parameters:
size- the initial capacity
-
IntArrayBuilder
public IntArrayBuilder(int[] ints) Create an IntArrayBuilder initialized with a copy of the given array.- Parameters:
ints- the initial values to copy into this builder
-
-
Method Details
-
append
Append an array of integers to this builder.- Parameters:
str- the integers to append- Returns:
- this builder for method chaining
-
append
Append a single integer to this builder.- Parameters:
c- the integer to append- Returns:
- this builder for method chaining
-
toArray
public int[] toArray()Return the contents of this builder as a new int array. If the internal buffer is exactly the right size, it is returned directly to avoid a copy. The builder should not be used after calling this method.- Returns:
- an array containing all appended integers
-
size
public int size()Return the number of integers currently in this builder.- Returns:
- the current size
-
deleteLastEntry
public void deleteLastEntry()Remove the last entry from this builder. If the builder is empty, this method does nothing.
-