com.cohort.array
Class CharArray

java.lang.Object
  extended by com.cohort.array.PrimitiveArray
      extended by com.cohort.array.CharArray

public class CharArray
extends PrimitiveArray

CharArray is a thin shell over a char[] with methods like ArrayList's methods; it extends PrimitiveArray.

This class uses Char.MAX_VALUE to represent a missing value (NaN).


Field Summary
 char[] array
          This is the main data structure.
 
Fields inherited from class com.cohort.array.PrimitiveArray
CLASS_INDEX_BYTE, CLASS_INDEX_CHAR, CLASS_INDEX_DOUBLE, CLASS_INDEX_FLOAT, CLASS_INDEX_INT, CLASS_INDEX_LONG, CLASS_INDEX_SHORT, CLASS_INDEX_STRING, size, STATS_MAX, STATS_MIN, STATS_N, STATS_SUM
 
Constructor Summary
CharArray()
          A constructor for a capacity of 8 elements.
CharArray(char[] anArray)
          A constructor which (at least initially) uses the array and all its elements ('size' will equal anArray.length).
CharArray(int capacity, boolean active)
          A constructor for a specified number of elements.
CharArray(PrimitiveArray primitiveArray)
          This constructs a CharArray from the PrimitiveArray via append().
 
Method Summary
 void add(char value)
          This adds an item to the array (increasing 'size' by 1).
 void add(char[] ar)
          This adds all the values from ar.
 void add(int index, char value)
          This inserts an item into the array (increasing 'size' by 1).
 void addDouble(double value)
          This adds an element to the array.
 void addFloat(float value)
          This adds an element to the array.
 void addFromPA(PrimitiveArray otherPA, int otherIndex)
          This adds an element from another PrimitiveArray.
 void addInt(int value)
          This adds an element to the array.
 void addLong(long value)
          This adds an element to the array.
 void addN(int n, char value)
          This adds n copies of value to the array (increasing 'size' by n).
 void addNDoubles(int n, double value)
          This adds n doubles to the array.
 void addNStrings(int n, java.lang.String value)
          This adds n Strings to the array.
 void addString(int index, java.lang.String value)
          This adds an element to the array at the specified index.
 void addString(java.lang.String value)
          This adds an element to the array.
 void append(PrimitiveArray primitiveArray)
          This appends the data in another primitiveArray to the current data.
 int capacity()
          This returns the current capacity (number of elements) of the internal data array.
 int compare(int index1, int index2)
          This compares the values in row1 and row2 for SortComparator, and returns a negative integer, zero, or a positive integer if the value at index1 is less than, equal to, or greater than the value at index2.
 void copy(int from, int to)
          This copies the value in row 'from' to row 'to'.
 java.lang.Class elementClass()
          This returns the class (char.class) of the element type.
 int elementClassIndex()
          This returns the class index (CLASS_INDEX_CHAR of the element type.
 void ensureCapacity(long minCapacity)
          This ensures that the capacity is at least 'minCapacity'.
 boolean equals(java.lang.Object o)
          Test if o is an CharArray with the same size and values.
 int firstTie()
          This tests for adjacent tied values and returns the index of the first tied value.
 char get(int index)
          This gets a specified element.
 double getDouble(int index)
          Return a value from the array as a double.
 float getFloat(int index)
          Return a value from the array as a float.
 int getInt(int index)
          Return a value from the array as an int.
 long getLong(int index)
          Return a value from the array as a long.
 int[] getNMinMaxIndex()
          This finds the number of non-missing values, and the index of the min and max value.
 java.lang.String getString(int index)
          Return a value from the array as a String.
 int hashCode()
          This returns the hashcode for this byteArray (dependent only on values, not capacity).
 int indexOf(char lookFor)
          This finds the first instance of 'lookFor' starting at index 'startIndex'.
 int indexOf(char lookFor, int startIndex)
          This finds the first instance of 'lookFor' starting at index 'startIndex'.
 int indexOf(java.lang.String lookFor, int startIndex)
          This finds the first instance of 'lookFor' starting at index 'startIndex'.
 void internalizeFromDODS(java.io.DataInputStream dis)
          This reads/appends char values to this PrimitiveArray from a DODS DataInputStream, and is thus the complement of externalizeForDODS.
 java.lang.String isAscending()
          This tests if the values in the array are sorted in ascending order (tied is ok).
 java.lang.String isDescending()
          This tests if the values in the array are sorted in descending order (tied is ok).
 java.lang.String isEvenlySpaced()
          This tests if the values in the array are exactly evenly spaced (ascending or descending).
 void justKeep(java.util.BitSet bitset)
          This just keeps the rows for the 'true' values in the bitset.
 int lastIndexOf(char lookFor, int startIndex)
          This finds the last instance of 'lookFor' starting at index 'startIndex'.
 int lastIndexOf(java.lang.String lookFor, int startIndex)
          This finds the last instance of 'lookFor' starting at index 'startIndex'.
 PrimitiveArray makeIndices(IntArray indices)
          This populates 'indices' with the indices (ranks) of the values in this CharArray (ties get the same index).
 java.lang.String maxValue()
          This returns the maximum value that can be held by this class.
 java.lang.String minValue()
          This returns the minimum value that can be held by this class.
 void move(int first, int last, int destination)
          Moves elements 'first' through 'last' (inclusive) to 'destination'.
static double rafReadDouble(java.io.RandomAccessFile raf, long start, long index)
          This reads one value from a randomAccessFile.
static void rafWriteDouble(java.io.RandomAccessFile raf, double value)
          This writes one value to a randomAccessFile at the current position.
static void rafWriteDouble(java.io.RandomAccessFile raf, long start, long index, double value)
          This writes one value to a randomAccessFile.
 void readDis(java.io.DataInputStream dis, int n)
          This reads/adds n elements from a DataInputStream.
 void remove(int index)
          This removes the specified element.
 void removeRange(int from, int to)
          This removes the specified range of elements.
 void reorder(int[] rank)
          This reorders the values in 'array' based on rank.
 void set(int index, char value)
          This sets a specified element.
 void setDouble(int index, double d)
          Set a value in the array as a double.
 void setFloat(int index, float d)
          Set a value in the array as a float.
 void setFromPA(int index, PrimitiveArray otherPA, int otherIndex)
          This sets an element from another PrimitiveArray.
 void setInt(int index, int i)
          Set a value in the array as an int.
 void setLong(int index, long i)
          Set a value in the array as a long.
 void setString(int index, java.lang.String s)
          Set a value in the array as a String.
 void sort()
          This sorts the elements in ascending order.
 PrimitiveArray subset(int startIndex, int stride, int stopIndex)
          This makes a new subset of this PrimitiveArray based on startIndex, stride, and stopIndex.
 int switchFromTo(java.lang.String tFrom, java.lang.String tTo)
          This changes all instances of the first value to the second value.
static void test()
          This tests the methods of this class.
 java.lang.String testEquals(java.lang.Object o)
          Test if o is an CharArray with the same size and values, but returns a String describing the difference (or "" if equal).
 char[] toArray()
          This returns an array (perhaps 'array') which has 'size' elements.
 double[] toDoubleArray()
          This returns a double[] (perhaps 'array') which has 'size' elements.
 java.lang.Object toObjectArray()
          This returns a primitive[] (perhaps 'array') which has 'size' elements.
 java.lang.String toString()
          This converts the elements into a comma-separated String.
 java.lang.String[] toStringArray()
          This returns a String[] which has 'size' elements.
 void trimToSize()
          If size != capacity, this makes a new 'array' of size 'size' so capacity will equal size.
 int writeDos(java.io.DataOutputStream dos, int i)
          This writes one element to a DataOutputStream.
 
Methods inherited from class com.cohort.array.PrimitiveArray
addOffsetScale, addOffsetScale, almostEqual, append, binaryFindClosest, binaryFindFirstGAE5, binaryFindFirstGE, binaryFindLastLAE5, binaryFindLastLE, binarySearch, calculateStats, clear, clone, compareIgnoreCase, convertToStandardMissingValues, copyRow, csvFactory, diff, diffIndex, diffString, displayStats, elementClassString, elementClassToString, elementSize, elementSize, elementSize, elementStringToClass, ensureAscending, externalizeForDODS, externalizeForDODS, factory, factory, factory, getMissingValue, getNiceDouble, getSqlTypeString, inCommon, indexOf, isIntegerType, lastIndexOf, linearFindClosest, main, merge, rafBinarySearch, rafFactory, rafFirstGAE5, rafFirstGE, rafLastLAE5, rafLastLE, rafReadDouble, rafWriteDouble, rafWriteDouble, rank, rankIgnoreCase, removeDuplicates, removeDuplicates, removeDuplicates, reverse, scaleAddOffset, scaleAddOffset, simplify, size, sort, sortIgnoreCase, sortIgnoreCase, sqlFactory, ssvFactory, statsString, strideWillFind, switchFakeMissingValueToNaN, switchNaNToFakeMissingValue, toJsonCsvString, writeDos
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

array

public char[] array
This is the main data structure. This should be private, but is public so you can manipulate it if you promise to be careful. Note that if the PrimitiveArray's capacity is increased, the PrimitiveArray will use a different array for storage.

Constructor Detail

CharArray

public CharArray()
A constructor for a capacity of 8 elements. The initial 'size' will be 0.


CharArray

public CharArray(PrimitiveArray primitiveArray)
This constructs a CharArray from the PrimitiveArray via append().

Parameters:
primitiveArray - a primitiveArray of any type

CharArray

public CharArray(int capacity,
                 boolean active)
A constructor for a specified number of elements. The initial 'size' will be 0.

Parameters:
capacity - creates an CharArray with the specified initial capacity.
active - if true, size will be set to capacity and all elements will equal 0; else size = 0.
Throws:
java.lang.Exception - if trouble.

CharArray

public CharArray(char[] anArray)
A constructor which (at least initially) uses the array and all its elements ('size' will equal anArray.length).

Parameters:
anArray - the array to be used as this object's array.
Method Detail

capacity

public int capacity()
This returns the current capacity (number of elements) of the internal data array.

Specified by:
capacity in class PrimitiveArray
Returns:
the current capacity (number of elements) of the internal data array.

hashCode

public int hashCode()
This returns the hashcode for this byteArray (dependent only on values, not capacity). WARNING: the algorithm used may change in future versions.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashcode for this byteArray (dependent only on values, not capacity)

subset

public PrimitiveArray subset(int startIndex,
                             int stride,
                             int stopIndex)
This makes a new subset of this PrimitiveArray based on startIndex, stride, and stopIndex.

Specified by:
subset in class PrimitiveArray
Parameters:
startIndex - must be a valid index
stride - must be at least 1
stopIndex - (inclusive) must be >= startIndex and < size.
Returns:
a new PrimitiveArray with the desired subset. It will have a new backing array with a capacity equal to its size.

elementClass

public java.lang.Class elementClass()
This returns the class (char.class) of the element type.

Specified by:
elementClass in class PrimitiveArray
Returns:
the class (char.class) of the element type.

elementClassIndex

public int elementClassIndex()
This returns the class index (CLASS_INDEX_CHAR of the element type.

Specified by:
elementClassIndex in class PrimitiveArray
Returns:
the class index (CLASS_INDEX_CHAR) of the element type.

add

public void add(char value)
This adds an item to the array (increasing 'size' by 1).

Parameters:
value - the value to be added to the array

add

public void add(char[] ar)
This adds all the values from ar.

Parameters:
ar - an array

addN

public void addN(int n,
                 char value)
This adds n copies of value to the array (increasing 'size' by n).

Parameters:
n - if less than 0, this throws Exception
value - the value to be added to the array. n < 0 throws an Exception.

add

public void add(int index,
                char value)
This inserts an item into the array (increasing 'size' by 1).

Parameters:
index - the position where the value should be inserted.
value - the value to be inserted into the array

addString

public void addString(int index,
                      java.lang.String value)
This adds an element to the array at the specified index.

Specified by:
addString in class PrimitiveArray
Parameters:
index - 0..
value - the value, as a String.

addNStrings

public void addNStrings(int n,
                        java.lang.String value)
This adds n Strings to the array.

Specified by:
addNStrings in class PrimitiveArray
Parameters:
n - the number of times 'value' should be added
value - the value, as a String.

addString

public void addString(java.lang.String value)
This adds an element to the array.

Specified by:
addString in class PrimitiveArray
Parameters:
value - the value, as a String.

addFloat

public void addFloat(float value)
This adds an element to the array.

Specified by:
addFloat in class PrimitiveArray
Parameters:
value - the float value

addDouble

public void addDouble(double value)
This adds an element to the array.

Specified by:
addDouble in class PrimitiveArray
Parameters:
value - the value, as a double.

addNDoubles

public void addNDoubles(int n,
                        double value)
This adds n doubles to the array.

Specified by:
addNDoubles in class PrimitiveArray
Parameters:
n - the number of times 'value' should be added
value - the value, as a double.

addInt

public void addInt(int value)
This adds an element to the array.

Specified by:
addInt in class PrimitiveArray
Parameters:
value - the value, as an int.

addLong

public void addLong(long value)
This adds an element to the array.

Specified by:
addLong in class PrimitiveArray
Parameters:
value - the value, as a long.

addFromPA

public void addFromPA(PrimitiveArray otherPA,
                      int otherIndex)
This adds an element from another PrimitiveArray.

Specified by:
addFromPA in class PrimitiveArray
Parameters:
otherPA -
otherIndex -

setFromPA

public void setFromPA(int index,
                      PrimitiveArray otherPA,
                      int otherIndex)
This sets an element from another PrimitiveArray.

Specified by:
setFromPA in class PrimitiveArray
Parameters:
index - the index to be set
otherPA -
otherIndex -

remove

public void remove(int index)
This removes the specified element.

Specified by:
remove in class PrimitiveArray
Parameters:
index - the element to be removed, 0 ... size-1
Throws:
java.lang.Exception - if trouble.

removeRange

public void removeRange(int from,
                        int to)
This removes the specified range of elements.

Specified by:
removeRange in class PrimitiveArray
Parameters:
from - the first element to be removed, 0 ... size
to - one after the last element to be removed, from ... size
Throws:
java.lang.Exception - if trouble.

move

public void move(int first,
                 int last,
                 int destination)
Moves elements 'first' through 'last' (inclusive) to 'destination'.

Specified by:
move in class PrimitiveArray
Parameters:
first - the first to be move
last - (exclusive)
destination - the destination, can't be in the range 'first+1..last-1'.
Throws:
java.lang.Exception - if trouble

justKeep

public void justKeep(java.util.BitSet bitset)
This just keeps the rows for the 'true' values in the bitset. Rows that aren't kept are removed. The resulting PrimitiveArray is compacted (i.e., it has a smaller size()).

Specified by:
justKeep in class PrimitiveArray
Parameters:
bitset -

ensureCapacity

public void ensureCapacity(long minCapacity)
This ensures that the capacity is at least 'minCapacity'.

Specified by:
ensureCapacity in class PrimitiveArray
Parameters:
minCapacity - the minimum acceptable capacity. minCapacity is type long, but >= Integer.MAX_VALUE will throw exception.

toArray

public char[] toArray()
This returns an array (perhaps 'array') which has 'size' elements.

Returns:
an array (perhaps 'array') which has 'size' elements.

toObjectArray

public java.lang.Object toObjectArray()
This returns a primitive[] (perhaps 'array') which has 'size' elements.

Specified by:
toObjectArray in class PrimitiveArray
Returns:
a primitive[] (perhaps 'array') which has 'size' elements.

toDoubleArray

public double[] toDoubleArray()
This returns a double[] (perhaps 'array') which has 'size' elements.

Specified by:
toDoubleArray in class PrimitiveArray
Returns:
a double[] (perhaps 'array') which has 'size' elements. Character.MAX_VALUE is converted to Double.NaN.

toStringArray

public java.lang.String[] toStringArray()
This returns a String[] which has 'size' elements.

Specified by:
toStringArray in class PrimitiveArray
Returns:
a String[] which has 'size' elements. This treats chars as unsigned shorts. Character.MAX_VALUE appears as "".

get

public char get(int index)
This gets a specified element.

Parameters:
index - 0 ... size-1
Throws:
java.lang.Exception - if trouble.

set

public void set(int index,
                char value)
This sets a specified element.

Parameters:
index - 0 ... size-1
value - the value for that element
Throws:
java.lang.Exception - if trouble.

getInt

public int getInt(int index)
Return a value from the array as an int.

Specified by:
getInt in class PrimitiveArray
Parameters:
index - the index number 0 ... size-1
Returns:
the value as an int. Character.MAX_VALUE is returned as Integer.MAX_VALUE.
Throws:
java.lang.Exception - if trouble.

setInt

public void setInt(int index,
                   int i)
Set a value in the array as an int.

Specified by:
setInt in class PrimitiveArray
Parameters:
index - the index number 0 .. size-1
i - the value. For numeric PrimitiveArray's, it is narrowed if needed by methods like Math2.narrowToChar(i).
Throws:
java.lang.Exception - if trouble.

getLong

public long getLong(int index)
Return a value from the array as a long.

Specified by:
getLong in class PrimitiveArray
Parameters:
index - the index number 0 ... size-1
Returns:
the value as a long. Character.MAX_VALUE is returned as Long.MAX_VALUE.
Throws:
java.lang.Exception - if trouble.

setLong

public void setLong(int index,
                    long i)
Set a value in the array as a long.

Specified by:
setLong in class PrimitiveArray
Parameters:
index - the index number 0 .. size-1
i - the value. For numeric PrimitiveArray's, it is narrowed if needed by methods like Math2.narrowToChar(long).
Throws:
java.lang.Exception - if trouble.

getFloat

public float getFloat(int index)
Return a value from the array as a float.

Specified by:
getFloat in class PrimitiveArray
Parameters:
index - the index number 0 .. size-1
Returns:
the value as a float. String values are parsed with String2.parseFloat and so may return Float.NaN. Character.MAX_VALUE is returned as Float.NaN.
Throws:
java.lang.Exception - if trouble.

setFloat

public void setFloat(int index,
                     float d)
Set a value in the array as a float.

Specified by:
setFloat in class PrimitiveArray
Parameters:
index - the index number 0 .. size-1
d - the value. For numeric PrimitiveArray, it is narrowed if needed by methods like Math2.roundToChar(d).
Throws:
java.lang.Exception - if trouble.

getDouble

public double getDouble(int index)
Return a value from the array as a double.

Specified by:
getDouble in class PrimitiveArray
Parameters:
index - the index number 0 .. size-1
Returns:
the value as a double. String values are parsed with String2.parseDouble and so may return Double.NaN. Character.MAX_VALUE is returned as Double.NaN.
Throws:
java.lang.Exception - if trouble.

setDouble

public void setDouble(int index,
                      double d)
Set a value in the array as a double.

Specified by:
setDouble in class PrimitiveArray
Parameters:
index - the index number 0 .. size-1
d - the value. For numeric PrimitiveArray, it is narrowed if needed by methods like Math2.roundToChar(d).
Throws:
java.lang.Exception - if trouble.

getString

public java.lang.String getString(int index)
Return a value from the array as a String.

Specified by:
getString in class PrimitiveArray
Parameters:
index - the index number 0 ..
Returns:
This returns (int)(ar[index]), or "" for NaN or infinity.
Throws:
java.lang.Exception - if trouble.

setString

public void setString(int index,
                      java.lang.String s)
Set a value in the array as a String.

Specified by:
setString in class PrimitiveArray
Parameters:
index - the index number 0 ..
s - the value. For numeric PrimitiveArray's, it is parsed with String2.parseInt and narrowed by Math2.narrowToChar(i).
Throws:
java.lang.Exception - if trouble.

indexOf

public int indexOf(char lookFor)
This finds the first instance of 'lookFor' starting at index 'startIndex'.

Parameters:
lookFor - the value to be looked for
Returns:
the index where 'lookFor' is found, or -1 if not found.

indexOf

public int indexOf(char lookFor,
                   int startIndex)
This finds the first instance of 'lookFor' starting at index 'startIndex'.

Parameters:
lookFor - the value to be looked for
startIndex - 0 ... size-1
Returns:
the index where 'lookFor' is found, or -1 if not found.

indexOf

public int indexOf(java.lang.String lookFor,
                   int startIndex)
This finds the first instance of 'lookFor' starting at index 'startIndex'. Here char is treated as an insigned short, so lookFor could be e.g., "65".

Specified by:
indexOf in class PrimitiveArray
Parameters:
lookFor - the value to be looked for
startIndex - 0 ... size-1
Returns:
the index where 'lookFor' is found, or -1 if not found.

lastIndexOf

public int lastIndexOf(char lookFor,
                       int startIndex)
This finds the last instance of 'lookFor' starting at index 'startIndex'.

Parameters:
lookFor - the value to be looked for
startIndex - 0 ... size-1
Returns:
the index where 'lookFor' is found, or -1 if not found.

lastIndexOf

public int lastIndexOf(java.lang.String lookFor,
                       int startIndex)
This finds the last instance of 'lookFor' starting at index 'startIndex'. Here char is treated as an insigned short, so lookFor could be e.g., "65".

Specified by:
lastIndexOf in class PrimitiveArray
Parameters:
lookFor - the value to be looked for
startIndex - 0 ... size-1
Returns:
the index where 'lookFor' is found, or -1 if not found.

trimToSize

public void trimToSize()
If size != capacity, this makes a new 'array' of size 'size' so capacity will equal size.

Specified by:
trimToSize in class PrimitiveArray

equals

public boolean equals(java.lang.Object o)
Test if o is an CharArray with the same size and values.

Overrides:
equals in class java.lang.Object
Parameters:
o -
Returns:
true if equal. o=null throws an exception.

testEquals

public java.lang.String testEquals(java.lang.Object o)
Test if o is an CharArray with the same size and values, but returns a String describing the difference (or "" if equal).

Specified by:
testEquals in class PrimitiveArray
Parameters:
o -
Returns:
a String describing the difference (or "" if equal). o=null throws an exception.

toString

public java.lang.String toString()
This converts the elements into a comma-separated String.

Specified by:
toString in class PrimitiveArray
Returns:
the comma-separated String representation of the values (with chars acting like unsigned shorts).

sort

public void sort()
This sorts the elements in ascending order. To get the elements in reverse order, just read from the end of the list to the beginning.

Specified by:
sort in class PrimitiveArray

compare

public int compare(int index1,
                   int index2)
This compares the values in row1 and row2 for SortComparator, and returns a negative integer, zero, or a positive integer if the value at index1 is less than, equal to, or greater than the value at index2. Currently, this does not checking of the range of index1 and index2, so the caller should be careful.

Specified by:
compare in class PrimitiveArray
Parameters:
index1 - an index number 0 ... size-1
index2 - an index number 0 ... size-1
Returns:
returns a negative integer, zero, or a positive integer if the value at index1 is less than, equal to, or greater than the value at index2. Think "array[index1] - array[index2]".

copy

public void copy(int from,
                 int to)
This copies the value in row 'from' to row 'to'. This does not check that 'from' and 'to' are valid; the caller should be careful. The value for 'from' is unchanged.

Specified by:
copy in class PrimitiveArray
Parameters:
from - an index number 0 ... size-1
to - an index number 0 ... size-1

reorder

public void reorder(int[] rank)
This reorders the values in 'array' based on rank.

Specified by:
reorder in class PrimitiveArray
Parameters:
rank - is an int with values (0 ... size-1) which points to the row number for a row with a specific rank (e.g., rank[0] is the row number of the first item in the sorted list, rank[1] is the row number of the second item in the sorted list, ...).

writeDos

public int writeDos(java.io.DataOutputStream dos,
                    int i)
             throws java.lang.Exception
This writes one element to a DataOutputStream.

Specified by:
writeDos in class PrimitiveArray
Parameters:
dos - the DataOutputStream
i - the index of the element to be written
Returns:
the number of bytes used for this element (for Strings, this varies; for others it is consistent)
Throws:
java.lang.Exception - if trouble

readDis

public void readDis(java.io.DataInputStream dis,
                    int n)
             throws java.lang.Exception
This reads/adds n elements from a DataInputStream.

Specified by:
readDis in class PrimitiveArray
Parameters:
dis - the DataInputStream
n - the number of elements to be read/added
Throws:
java.lang.Exception - if trouble

internalizeFromDODS

public void internalizeFromDODS(java.io.DataInputStream dis)
                         throws java.io.IOException
This reads/appends char values to this PrimitiveArray from a DODS DataInputStream, and is thus the complement of externalizeForDODS.

Specified by:
internalizeFromDODS in class PrimitiveArray
Parameters:
dis -
Throws:
java.io.IOException - if trouble

rafReadDouble

public static double rafReadDouble(java.io.RandomAccessFile raf,
                                   long start,
                                   long index)
                            throws java.lang.Exception
This reads one value from a randomAccessFile.

Parameters:
raf - the RandomAccessFile
start - the raf offset of the start of the array (nBytes)
index - the index of the desired value (0..)
Returns:
the requested value as a double
Throws:
java.lang.Exception - if trouble

rafWriteDouble

public static void rafWriteDouble(java.io.RandomAccessFile raf,
                                  double value)
                           throws java.lang.Exception
This writes one value to a randomAccessFile at the current position.

Parameters:
raf - the RandomAccessFile
value - the value which will be converted to this PrimitiveArray's type and then stored
Throws:
java.lang.Exception - if trouble

rafWriteDouble

public static void rafWriteDouble(java.io.RandomAccessFile raf,
                                  long start,
                                  long index,
                                  double value)
                           throws java.lang.Exception
This writes one value to a randomAccessFile.

Parameters:
raf - the RandomAccessFile
start - the raf offset of the start of the array (nBytes)
index - the index of the desired value (0..)
value - the value which will be converted to this PrimitiveArray's type and then stored
Throws:
java.lang.Exception - if trouble

append

public void append(PrimitiveArray primitiveArray)
This appends the data in another primitiveArray to the current data. WARNING: information may be lost from incoming primitiveArray this primitiveArray is of a simpler type.

Specified by:
append in class PrimitiveArray
Parameters:
primitiveArray - primitiveArray must be the same or a narrower data type, or the data will be narrowed with Math2.narrowToChar.

makeIndices

public PrimitiveArray makeIndices(IntArray indices)
This populates 'indices' with the indices (ranks) of the values in this CharArray (ties get the same index). For example, b,b,c,a returns 1,1,2,0.

Specified by:
makeIndices in class PrimitiveArray
Parameters:
indices - the intArray that will capture the indices of the values (ties get the same index). For example, b,b,c,a returns 1,1,2,0.
Returns:
a PrimitveArray (the same type as this class) with the unique values, sorted. If all the values are unique and already sorted, this returns 'this'.

switchFromTo

public int switchFromTo(java.lang.String tFrom,
                        java.lang.String tTo)
This changes all instances of the first value to the second value.

Specified by:
switchFromTo in class PrimitiveArray
Parameters:
tFrom - the original value (use "" or "NaN" for standard missingValue)
tTo - the new value (use "" or "NaN" for standard missingValue)
Returns:
the number of values switched

isAscending

public java.lang.String isAscending()
This tests if the values in the array are sorted in ascending order (tied is ok). The details of this test are geared toward determining if the values are suitable for binarySearch.

Specified by:
isAscending in class PrimitiveArray
Returns:
"" if the values in the array are sorted in ascending order (or tied); or an error message if not (i.e., if descending or unordered). If size is 0 or 1 (non-missing value), this returns "". A missing value returns an error message.

isDescending

public java.lang.String isDescending()
This tests if the values in the array are sorted in descending order (tied is ok).

Specified by:
isDescending in class PrimitiveArray
Returns:
"" if the values in the array are sorted in descending order (or tied); or an error message if not (i.e., if ascending or unordered). If size is 0 or 1 (non-missing value), this returns "". A missing value returns an error message.

firstTie

public int firstTie()
This tests for adjacent tied values and returns the index of the first tied value. Adjacent NaNs are treated as ties.

Specified by:
firstTie in class PrimitiveArray
Returns:
the index of the first tied value (or -1 if none).

isEvenlySpaced

public java.lang.String isEvenlySpaced()
This tests if the values in the array are exactly evenly spaced (ascending or descending).

Specified by:
isEvenlySpaced in class PrimitiveArray
Returns:
"" if the values in the array are exactly evenly spaced; or an error message if not. If size is 0 or 1, this returns "".

minValue

public java.lang.String minValue()
This returns the minimum value that can be held by this class.

Specified by:
minValue in class PrimitiveArray

maxValue

public java.lang.String maxValue()
This returns the maximum value that can be held by this class.

Specified by:
maxValue in class PrimitiveArray

getNMinMaxIndex

public int[] getNMinMaxIndex()
This finds the number of non-missing values, and the index of the min and max value.

Specified by:
getNMinMaxIndex in class PrimitiveArray
Returns:
int[3], [0]=the number of non-missing values, [1]=index of min value (if tie, index of last found; -1 if all mv), [2]=index of max value (if tie, index of last found; -1 if all mv).

test

public static void test()
                 throws java.lang.Throwable
This tests the methods of this class.

Throws:
java.lang.Throwable - if trouble.