net.aerith.misao.util
Class Array

java.lang.Object
  |
  +--net.aerith.misao.util.SortableArray
        |
        +--net.aerith.misao.util.Array

public class Array
extends SortableArray
implements Statisticable

The Array represents an array of data values with a funciton to sort.


Field Summary
protected  double[] array
          The buffer of data array.
protected  int size
          The size of buffer.
 
Fields inherited from class net.aerith.misao.util.SortableArray
COMPARE_EQUAL, COMPARE_LARGER, COMPARE_SMALLER, SORT_ASCENDANT, SORT_DESCENDANT, sort_index
 
Constructor Summary
Array(int buffer_size)
          Constructs an Array with a specified size of buffer.
 
Method Summary
 Array cloneArray()
          Creates a clone array.
 Array cloneArray(int new_size)
          Creates a clone array.
protected  int compare(int index1, int index2)
          Compares the two data represented by the specified index and returns which is smaller.
 int getArraySize()
          Gets the size of this array.
 int getDataCount()
          Gets the number of data.
 int getPeakIndex()
          Gets the location of the largest value.
 double getValueAt(int index)
          Gets the value of data at the specified location.
 int meanIndexOf(double value)
          Gets the mean location where the value is expected to go across the specified value.
 void set(int index, double value)
          Sets the value of data at the specified location.
 void setMovingAverage(int window_size)
          Calculates the moving average and sets the result into this array.
protected  void sort()
          Sorts this array itself based on the sorted index.
 
Methods inherited from class net.aerith.misao.util.SortableArray
quick_sort, sortAscendant, sortDescendant
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

array

protected double[] array
The buffer of data array.

size

protected int size
The size of buffer.
Constructor Detail

Array

public Array(int buffer_size)
Constructs an Array with a specified size of buffer. The buffer is set as 0.
Parameters:
buffer_size - the size of buffer to create.
Method Detail

getArraySize

public int getArraySize()
Gets the size of this array.
Overrides:
getArraySize in class SortableArray
Returns:
the size of this array.

getDataCount

public int getDataCount()
Gets the number of data.
Specified by:
getDataCount in interface Statisticable
Returns:
the number of data.

getValueAt

public double getValueAt(int index)
                  throws java.lang.IndexOutOfBoundsException
Gets the value of data at the specified location.
Specified by:
getValueAt in interface Statisticable
Parameters:
index - the location of the data.
Returns:
the value of data at the specified location.
Throws:
java.lang.IndexOutOfBoundsException - if specified location is out of the data buffer.

set

public void set(int index,
                double value)
         throws java.lang.IndexOutOfBoundsException
Sets the value of data at the specified location.
Parameters:
index - the location to store the data.
value - the value of data.
Throws:
java.lang.IndexOutOfBoundsException - if specified location is out of the data buffer.

getPeakIndex

public int getPeakIndex()
Gets the location of the largest value. If there are some elements which have the same largest value, the location of the first element among them is returned.
Returns:
the location of the largest value.

meanIndexOf

public int meanIndexOf(double value)
Gets the mean location where the value is expected to go across the specified value. When all elements are smaller or larger than the specified value, which means the value never go across the specified value, -1 is returned.
Parameters:
value - the value.
Returns:
the mean location where the value is expected to go across the specified value.

setMovingAverage

public void setMovingAverage(int window_size)
Calculates the moving average and sets the result into this array.
Parameters:
window_size - the number of data to caluclate the moving average.

compare

protected int compare(int index1,
                      int index2)
Compares the two data represented by the specified index and returns which is smaller. If the first data is smaller, it returns COMPARE_SMALLER. If the first data is larger, it returns COMPARE_LARGER. If both the data are equal, it returns COMPARE_EQUAL.
Overrides:
compare in class SortableArray
Parameters:
index1 - the index to represent the first data to compare.
index2 - the index to represent the second data to compare.
Returns:
the number to represent the comparison result.

sort

protected void sort()
Sorts this array itself based on the sorted index. It is invoked in the sorting functions.
Overrides:
sort in class SortableArray

cloneArray

public Array cloneArray()
Creates a clone array.
Returns:
the new clone array.

cloneArray

public Array cloneArray(int new_size)
Creates a clone array.
Parameters:
new_size - the size of new array.
Returns:
the new clone array.