Package com.mckoi.util
Class BlockIntegerList.IntArrayListBlock
- java.lang.Object
-
- com.mckoi.util.IntegerListBlockInterface
-
- com.mckoi.util.BlockIntegerList.IntArrayListBlock
-
- Enclosing class:
- BlockIntegerList
public static class BlockIntegerList.IntArrayListBlock extends IntegerListBlockInterface
The block that contains the actual int values of the list. This is made public because it may be useful to derive from this class.
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
array
The array of int's stored in this block.protected int
count
The number of block entries in this list.-
Fields inherited from class com.mckoi.util.IntegerListBlockInterface
next, previous
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
IntArrayListBlock()
Blank protected constructor.IntArrayListBlock(int block_size)
Constructs the block to a specific size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInt(int val)
Adds an int to the block.int
binarySearch(java.lang.Object key, IndexComparator c)
Considers each int a reference to another structure, and the block sorted by these structures.int
bottomInt()
The bottom int in the list.boolean
canContain(int number)
Returns true if the block has enough room to fill with the given number of integers.void
clear()
Clears the object to be re-used.int
copyTo(int[] to, int offset)
Copies all the data from this block into the given int[] array.void
copyTo(IntegerListBlockInterface dest_block)
Copies all the data from this block into the given destination block.protected int[]
getArray(boolean immutable)
Returns the int[] array for this block.protected int
getArrayLength()
Returns the count of int's in this block.void
insertIntAt(int val, int pos)
Inserts an int at the given position.int
intAt(int pos)
Returns the int at the given position in the array.boolean
isEmpty()
Returns true if the block is empty.boolean
isFull()
Returns true if the block is full.int
iterativeSearch(int val)
Performs an iterative search through the int values in the list.int
iterativeSearch(int val, int position)
Performs an iterative search from the given position to the end of the list in the block.void
moveTo(IntegerListBlockInterface dest_block, int dest_index, int length)
Moves a set of values from the end of this block and inserts it into the given block at the destination index specified.int
removeIntAt(int pos)
Removes an Int from the specified position in the block.int
searchFirst(int val)
Assuming a sorted block, finds the first index in the block that equals the given value.int
searchFirst(java.lang.Object key, IndexComparator c)
Considers each int a reference to another structure, and the block sorted by these structures.int
searchLast(int val)
Assuming a sorted block, finds the first index in the block that equals the given value.int
searchLast(java.lang.Object key, IndexComparator c)
Considers each int a reference to another structure, and the block sorted by these structures.int
setIntAt(int val, int pos)
Sets an int at the given position, overwriting anything that was previously there.int
size()
Returns the number of entries in this block.int
topInt()
The top int in the list.java.lang.String
toString()
Converts the block into a String.-
Methods inherited from class com.mckoi.util.IntegerListBlockInterface
hasChanged
-
-
-
-
Method Detail
-
getArray
protected int[] getArray(boolean immutable)
Returns the int[] array for this block. If 'immutable' is true then the array object is guarenteed to not be mutated.
-
getArrayLength
protected int getArrayLength()
Returns the count of int's in this block.
-
size
public final int size()
Returns the number of entries in this block.- Specified by:
size
in classIntegerListBlockInterface
-
isFull
public final boolean isFull()
Returns true if the block is full.- Specified by:
isFull
in classIntegerListBlockInterface
-
isEmpty
public final boolean isEmpty()
Returns true if the block is empty.- Specified by:
isEmpty
in classIntegerListBlockInterface
-
canContain
public final boolean canContain(int number)
Returns true if the block has enough room to fill with the given number of integers.- Specified by:
canContain
in classIntegerListBlockInterface
-
topInt
public int topInt()
The top int in the list.- Specified by:
topInt
in classIntegerListBlockInterface
-
bottomInt
public int bottomInt()
The bottom int in the list.- Specified by:
bottomInt
in classIntegerListBlockInterface
-
intAt
public final int intAt(int pos)
Returns the int at the given position in the array.- Specified by:
intAt
in classIntegerListBlockInterface
-
addInt
public final void addInt(int val)
Adds an int to the block.- Specified by:
addInt
in classIntegerListBlockInterface
-
removeIntAt
public final int removeIntAt(int pos)
Removes an Int from the specified position in the block.- Specified by:
removeIntAt
in classIntegerListBlockInterface
-
insertIntAt
public final void insertIntAt(int val, int pos)
Inserts an int at the given position.- Specified by:
insertIntAt
in classIntegerListBlockInterface
-
setIntAt
public final int setIntAt(int val, int pos)
Sets an int at the given position, overwriting anything that was previously there. It returns the value that was previously at the element.- Specified by:
setIntAt
in classIntegerListBlockInterface
-
moveTo
public final void moveTo(IntegerListBlockInterface dest_block, int dest_index, int length)
Moves a set of values from the end of this block and inserts it into the given block at the destination index specified. Assumes the destination block has enough room to store the set.- Specified by:
moveTo
in classIntegerListBlockInterface
-
copyTo
public final void copyTo(IntegerListBlockInterface dest_block)
Copies all the data from this block into the given destination block.- Specified by:
copyTo
in classIntegerListBlockInterface
-
copyTo
public final int copyTo(int[] to, int offset)
Copies all the data from this block into the given int[] array. Returns the number of 'int' values copied.- Specified by:
copyTo
in classIntegerListBlockInterface
-
clear
public final void clear()
Clears the object to be re-used.- Specified by:
clear
in classIntegerListBlockInterface
-
iterativeSearch
public int iterativeSearch(int val)
Performs an iterative search through the int values in the list. If it's found the index of the value is returned, else it returns -1.- Specified by:
iterativeSearch
in classIntegerListBlockInterface
-
iterativeSearch
public int iterativeSearch(int val, int position)
Performs an iterative search from the given position to the end of the list in the block. If it's found the index of the value is returned, else it returns -1.- Specified by:
iterativeSearch
in classIntegerListBlockInterface
-
binarySearch
public final int binarySearch(java.lang.Object key, IndexComparator c)
Considers each int a reference to another structure, and the block sorted by these structures. The method performs a binary search.- Specified by:
binarySearch
in classIntegerListBlockInterface
-
searchFirst
public final int searchFirst(java.lang.Object key, IndexComparator c)
Considers each int a reference to another structure, and the block sorted by these structures. Finds the first index in the block that equals the given key.- Specified by:
searchFirst
in classIntegerListBlockInterface
-
searchLast
public final int searchLast(java.lang.Object key, IndexComparator c)
Considers each int a reference to another structure, and the block sorted by these structures. Finds the first index in the block that equals the given key.- Specified by:
searchLast
in classIntegerListBlockInterface
-
searchFirst
public final int searchFirst(int val)
Assuming a sorted block, finds the first index in the block that equals the given value.- Specified by:
searchFirst
in classIntegerListBlockInterface
-
searchLast
public final int searchLast(int val)
Assuming a sorted block, finds the first index in the block that equals the given value.- Specified by:
searchLast
in classIntegerListBlockInterface
-
toString
public java.lang.String toString()
Converts the block into a String.- Overrides:
toString
in classjava.lang.Object
-
-