org.foray.common.util
Class IntArrayBuilder

java.lang.Object
  extended by org.foray.common.util.IntArrayBuilder
All Implemented Interfaces:
org.axsl.common.IntSequence

public class IntArrayBuilder
extends Object
implements org.axsl.common.IntSequence

A resizable collection of primitive Integer.TYPE, a subset of what is available in StringBuilder, but with ints instead of chars.


Constructor Summary
IntArrayBuilder(int initialCapacity)
          Constructor.
 
Method Summary
 IntArrayBuilder append(int intToAppend)
          Append an int to this structure.
 IntArrayBuilder delete(int start, int end)
          Removes the ints in a range of this sequence.
 IntArrayBuilder deleteIntAt(int index)
          Removes the value at a given index.
 int intAt(int index)
           
 int length()
           
 IntArrayBuilder replace(int index, int newValue)
          Replaces the value at a given index with a new value.
 org.axsl.common.IntSequence subSequence(int start, int end)
           
 int[] toArray()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntArrayBuilder

public IntArrayBuilder(int initialCapacity)
Constructor.

Parameters:
initialCapacity - The initial size of the internal array.
Method Detail

length

public int length()
Specified by:
length in interface org.axsl.common.IntSequence

intAt

public int intAt(int index)
Specified by:
intAt in interface org.axsl.common.IntSequence

subSequence

public org.axsl.common.IntSequence subSequence(int start,
                                               int end)
Specified by:
subSequence in interface org.axsl.common.IntSequence

toArray

public int[] toArray()
Specified by:
toArray in interface org.axsl.common.IntSequence

toString

public String toString()
Overrides:
toString in class Object

append

public IntArrayBuilder append(int intToAppend)
Append an int to this structure.

Parameters:
intToAppend - The int to append.
Returns:
This object.

replace

public IntArrayBuilder replace(int index,
                               int newValue)
Replaces the value at a given index with a new value.

Parameters:
index - The index whose value should be replaced.
newValue - The new value to place at index.
Returns:
This object.
Throws:
IndexOutOfBoundsException - If the index is negative or greater than or equal to length().

deleteIntAt

public IntArrayBuilder deleteIntAt(int index)
Removes the value at a given index.

Parameters:
index - The index whose value should be deleted.
Returns:
This object.
Throws:
IndexOutOfBoundsException - If the index is negative or greater than or equal to length().

delete

public IntArrayBuilder delete(int start,
                              int end)
Removes the ints in a range of this sequence. The range begins at the specified start and extends to the int at index end - 1 or to the end of the sequence if no such int exists. If start is equal to end, no changes are made.

Parameters:
start - The beginning index, inclusive.
end - The ending index, exclusive.
Returns:
This object.
Throws:
IndexOutOfBoundsException - If start is negative, greater than length(), or greater than end.


Copyright © 2017. All rights reserved.