iitb.con.util
Class Sorted2DIntArray

java.lang.Object
  extended by iitb.con.util.Sorted2DIntArray

public class Sorted2DIntArray
extends java.lang.Object

Sorted 2D Integer Array consists of two columns (key-value) and the values are maintained in sorted order according to the key. It is an unbound array and handles duplicate values.


Constructor Summary
Sorted2DIntArray(java.nio.ByteBuffer buffer)
           
Sorted2DIntArray(int size)
          Constructor with full specification.
 
Method Summary
 int add(int value1, int value2)
          Add a value to the array, appending it after the current values.
 void clear()
          Set the array to the empty state.
 void dump()
          Prints the contents of the array
 void ensureCapacity(int min)
          Ensure that the array has the capacity for at least the specified number of values.
 int[][] get(int value1)
          Retrieve the value present at an index position in the array.
 boolean isValuePairExist(int value1, int value2)
          Checks if given value pair exists in the array
static void main(java.lang.String[] args)
           
 void remove(int value1)
          Remove a value from the array.
 void set(int value1, int value2)
          Sets the values based on the index match of value1 in the array.
 void setSize(int count)
          Sets the number of values currently present in the array.
 int size()
          Get the number of values currently present in the array.
 java.nio.ByteBuffer toBuffer()
          Returns the array contents as bytes in the form of ByteBuffer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sorted2DIntArray

public Sorted2DIntArray(java.nio.ByteBuffer buffer)

Sorted2DIntArray

public Sorted2DIntArray(int size)
Constructor with full specification.

Parameters:
size - number of int values initially allowed in array
Method Detail

add

public final int add(int value1,
                     int value2)
Add a value to the array, appending it after the current values.

Parameters:
value1 - value to be added
value2 - value to be added
Returns:
index number of added element

clear

public final void clear()
Set the array to the empty state.


dump

public void dump()
Prints the contents of the array


ensureCapacity

public final void ensureCapacity(int min)
Ensure that the array has the capacity for at least the specified number of values.

Parameters:
min - minimum capacity to be guaranteed

get

public final int[][] get(int value1)
Retrieve the value present at an index position in the array.

Parameters:
value1 - rows to be retrieved using value1
Returns:
the rows based on the match of value1, returns NULL if there is no match

isValuePairExist

public final boolean isValuePairExist(int value1,
                                      int value2)
Checks if given value pair exists in the array

Parameters:
value1 - first column value (key)
value2 - second column value
Returns:
true if exists, else false

main

public static void main(java.lang.String[] args)

remove

public void remove(int value1)
Remove a value from the array. All values above the index removed are moved down one index position.

Parameters:
value1 - index of value1 to be removed

set

public final void set(int value1,
                      int value2)
Sets the values based on the index match of value1 in the array.

Parameters:
value1 - value used to located the index in the array
value2 - value to be set

setSize

public void setSize(int count)
Sets the number of values currently present in the array. If the new size is greater than the current size, the added values are initialized to 0.

Parameters:
count - number of values to be set

size

public final int size()
Get the number of values currently present in the array.

Returns:
count of values present

toBuffer

public java.nio.ByteBuffer toBuffer()
Returns the array contents as bytes in the form of ByteBuffer

Returns:
contents as ByteBuffer