|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.cohort.array.PrimitiveArray
com.cohort.array.ByteArray
public class ByteArray
ByteArray is a thin shell over a byte[] with methods like ArrayList's methods; it extends PrimitiveArray.
This class uses Byte.MAX_VALUE to represent a missing value (NaN).
| Field Summary | |
|---|---|
byte[] |
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 | |
|---|---|
ByteArray()
A constructor for a capacity of 8 elements. |
|
ByteArray(byte[] anArray)
A constructor which (at least initially) uses the array and all its elements ('size' will equal anArray.length). |
|
ByteArray(int capacity,
boolean active)
A constructor for a specified capacity. |
|
ByteArray(int first,
int last)
A special constructor for ByteArray: first, last, with an increment of 1. |
|
ByteArray(PrimitiveArray primitiveArray)
This constructs a ByteArray from the PrimitiveArray via append(). |
|
ByteArray(java.lang.String fileName)
A constructor which reads/adds the byte contents of a file EXACTLY. |
|
| Method Summary | |
|---|---|
void |
add(byte value)
This adds an item to the array (increasing 'size' by 1). |
void |
add(byte[] ar)
This adds all the values from ar. |
void |
add(byte[] ar,
int offset,
int nBytes)
This adds all the values from ar. |
void |
add(int index,
byte 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,
byte 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 (byte.class) of the element type. |
int |
elementClassIndex()
This returns the class index (CLASS_INDEX_BYTE) 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 ByteArray with the same size and values. |
void |
externalizeForDODS(java.io.DataOutputStream dos)
This writes all the data to a DataOutputStream in the DODS Array format (see www.opendap.org DAP 2.0 standard, section 7.3.2.1). |
void |
externalizeForDODS(java.io.DataOutputStream dos,
int i)
This writes one element to a DataOutputStream in the DODS Atomic-type format (see www.opendap.org DAP 2.0 standard, section 7.3.2). |
int |
firstTie()
This tests for adjacent tied values and returns the index of the first tied value. |
byte |
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(byte lookFor)
This finds the first instance of 'lookFor' starting at index 'startIndex'. |
int |
indexOf(byte 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 byte 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(byte 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 ByteArray (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,
byte 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 ByteArray with the same size and values, but returns a String describing the difference (or "" if equal). |
byte[] |
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)
This writes 'size' elements to a DataOutputStream. |
int |
writeDos(java.io.DataOutputStream dos,
int i)
This writes one element to a DataOutputStream. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public byte[] array
| Constructor Detail |
|---|
public ByteArray()
public ByteArray(PrimitiveArray primitiveArray)
primitiveArray - a primitiveArray of any type
public ByteArray(int capacity,
boolean active)
capacity - creates an ByteArray with the specified initial capacity.active - if true, size will be set to capacity and all elements
will equal 0; else size = 0.
java.lang.Exception - if trouble.public ByteArray(byte[] anArray)
anArray - the array to be used as this object's array.
public ByteArray(int first,
int last)
first - the value of the first element.last - the value of the last element (inclusive!).
java.lang.Exception - if trouble.
public ByteArray(java.lang.String fileName)
throws java.lang.Exception
fileName - is the (usually canonical) path (dir+name) for the file
java.lang.Exception - if trouble| Method Detail |
|---|
public int capacity()
capacity in class PrimitiveArraypublic int hashCode()
hashCode in class java.lang.Object
public PrimitiveArray subset(int startIndex,
int stride,
int stopIndex)
subset in class PrimitiveArraystartIndex - must be a valid indexstride - must be at least 1stopIndex - (inclusive) must be >= startIndex and < size.
public java.lang.Class elementClass()
elementClass in class PrimitiveArraypublic int elementClassIndex()
elementClassIndex in class PrimitiveArraypublic void add(byte value)
value - the value to be added to the arraypublic void add(byte[] ar)
ar - an array
public void add(byte[] ar,
int offset,
int nBytes)
ar - an array
public void addN(int n,
byte value)
n - if less than 0, this throws Exceptionvalue - the value to be added to the array.
n < 0 throws an Exception.
public void add(int index,
byte value)
index - the position where the value should be inserted.value - the value to be inserted into the array
public void addString(int index,
java.lang.String value)
addString in class PrimitiveArrayindex - 0..value - the value, as a String.
public void addNStrings(int n,
java.lang.String value)
addNStrings in class PrimitiveArrayn - the number of times 'value' should be addedvalue - the value, as a String.public void addString(java.lang.String value)
addString in class PrimitiveArrayvalue - the value, as a String.public void addFloat(float value)
addFloat in class PrimitiveArrayvalue - the float valuepublic void addDouble(double value)
addDouble in class PrimitiveArrayvalue - the value, as a double.
public void addNDoubles(int n,
double value)
addNDoubles in class PrimitiveArrayn - the number of times 'value' should be addedvalue - the value, as a double.public void addInt(int value)
addInt in class PrimitiveArrayvalue - the value, as an int.public void addLong(long value)
addLong in class PrimitiveArrayvalue - the value, as a long.
public void addFromPA(PrimitiveArray otherPA,
int otherIndex)
addFromPA in class PrimitiveArrayotherPA - otherIndex -
public void setFromPA(int index,
PrimitiveArray otherPA,
int otherIndex)
setFromPA in class PrimitiveArrayindex - the index to be setotherPA - otherIndex - public void remove(int index)
remove in class PrimitiveArrayindex - the element to be removed, 0 ... size-1
java.lang.Exception - if trouble.
public void removeRange(int from,
int to)
removeRange in class PrimitiveArrayfrom - the first element to be removed, 0 ... sizeto - one after the last element to be removed, from ... size
java.lang.Exception - if trouble.
public void move(int first,
int last,
int destination)
move in class PrimitiveArrayfirst - the first to be movelast - (exclusive)destination - the destination, can't be in the range 'first+1..last-1'.
java.lang.Exception - if troublepublic void justKeep(java.util.BitSet bitset)
justKeep in class PrimitiveArraybitset - public void ensureCapacity(long minCapacity)
ensureCapacity in class PrimitiveArrayminCapacity - the minimum acceptable capacity.
minCapacity is type long, but >= Integer.MAX_VALUE will throw exception.public byte[] toArray()
public java.lang.Object toObjectArray()
toObjectArray in class PrimitiveArraypublic double[] toDoubleArray()
toDoubleArray in class PrimitiveArraypublic java.lang.String[] toStringArray()
toStringArray in class PrimitiveArraypublic byte get(int index)
index - 0 ... size-1
java.lang.Exception - if trouble.
public void set(int index,
byte value)
index - 0 ... size-1value - the value for that element
java.lang.Exception - if trouble.public int getInt(int index)
getInt in class PrimitiveArrayindex - the index number 0 ... size-1
java.lang.Exception - if trouble.
public void setInt(int index,
int i)
setInt in class PrimitiveArrayindex - the index number 0 .. size-1i - the value. For numeric PrimitiveArray's, it is narrowed
if needed by methods like Math2.narrowToByte(i).
java.lang.Exception - if trouble.public long getLong(int index)
getLong in class PrimitiveArrayindex - the index number 0 ... size-1
java.lang.Exception - if trouble.
public void setLong(int index,
long i)
setLong in class PrimitiveArrayindex - the index number 0 .. size-1i - the value. For numeric PrimitiveArray's, it is narrowed
if needed by methods like Math2.narrowToByte(long).
java.lang.Exception - if trouble.public float getFloat(int index)
getFloat in class PrimitiveArrayindex - the index number 0 .. size-1
java.lang.Exception - if trouble.
public void setFloat(int index,
float d)
setFloat in class PrimitiveArrayindex - the index number 0 .. size-1d - the value. For numeric PrimitiveArray, it is narrowed
if needed by methods like Math2.roundToByte(d).
java.lang.Exception - if trouble.public double getDouble(int index)
getDouble in class PrimitiveArrayindex - the index number 0 .. size-1
java.lang.Exception - if trouble.
public void setDouble(int index,
double d)
setDouble in class PrimitiveArrayindex - the index number 0 .. size-1d - the value. For numeric PrimitiveArray, it is narrowed
if needed by methods like Math2.roundToByte(d).
java.lang.Exception - if trouble.public java.lang.String getString(int index)
getString in class PrimitiveArrayindex - the index number 0 ..
java.lang.Exception - if trouble.
public void setString(int index,
java.lang.String s)
setString in class PrimitiveArrayindex - the index number 0 ..s - the value. For numeric PrimitiveArray's, it is parsed
with String2.parseInt and narrowed by Math2.narrowToByte(i).
java.lang.Exception - if trouble.public int indexOf(byte lookFor)
lookFor - the value to be looked for
public int indexOf(byte lookFor,
int startIndex)
lookFor - the value to be looked forstartIndex - 0 ... size-1
public int indexOf(java.lang.String lookFor,
int startIndex)
indexOf in class PrimitiveArraylookFor - the value to be looked forstartIndex - 0 ... size-1
public int lastIndexOf(byte lookFor,
int startIndex)
lookFor - the value to be looked forstartIndex - 0 ... size-1
public int lastIndexOf(java.lang.String lookFor,
int startIndex)
lastIndexOf in class PrimitiveArraylookFor - the value to be looked forstartIndex - 0 ... size-1
public void trimToSize()
trimToSize in class PrimitiveArraypublic boolean equals(java.lang.Object o)
equals in class java.lang.Objecto -
public java.lang.String testEquals(java.lang.Object o)
testEquals in class PrimitiveArrayo -
public java.lang.String toString()
toString in class PrimitiveArraypublic void sort()
sort in class PrimitiveArray
public int compare(int index1,
int index2)
compare in class PrimitiveArrayindex1 - an index number 0 ... size-1index2 - an index number 0 ... size-1
public void copy(int from,
int to)
copy in class PrimitiveArrayfrom - an index number 0 ... size-1to - an index number 0 ... size-1public void reorder(int[] rank)
reorder in class PrimitiveArrayrank - 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, ...).
public int writeDos(java.io.DataOutputStream dos)
throws java.lang.Exception
writeDos in class PrimitiveArraydos - the DataOutputStream
java.lang.Exception - if trouble
public int writeDos(java.io.DataOutputStream dos,
int i)
throws java.lang.Exception
writeDos in class PrimitiveArraydos - the DataOutputStreami - the index of the element to be written
java.lang.Exception - if trouble
public void readDis(java.io.DataInputStream dis,
int n)
throws java.lang.Exception
readDis in class PrimitiveArraydis - the DataInputStreamn - the number of elements to be read/added
java.lang.Exception - if trouble
public void externalizeForDODS(java.io.DataOutputStream dos)
throws java.lang.Exception
externalizeForDODS in class PrimitiveArraydos -
java.lang.Exception - if trouble
public void externalizeForDODS(java.io.DataOutputStream dos,
int i)
throws java.lang.Exception
externalizeForDODS in class PrimitiveArraydos - i - the index of the element to be written
java.lang.Exception - if trouble
public void internalizeFromDODS(java.io.DataInputStream dis)
throws java.io.IOException
internalizeFromDODS in class PrimitiveArraydis -
java.io.IOException - if trouble
public static double rafReadDouble(java.io.RandomAccessFile raf,
long start,
long index)
throws java.lang.Exception
raf - the RandomAccessFilestart - the raf offset of the start of the array (nBytes)index - the index of the desired value (0..)
java.lang.Exception - if trouble
public static void rafWriteDouble(java.io.RandomAccessFile raf,
double value)
throws java.lang.Exception
raf - the RandomAccessFilevalue - the value which will be converted to this PrimitiveArray's
type and then stored
java.lang.Exception - if trouble
public static void rafWriteDouble(java.io.RandomAccessFile raf,
long start,
long index,
double value)
throws java.lang.Exception
raf - the RandomAccessFilestart - 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
java.lang.Exception - if troublepublic void append(PrimitiveArray primitiveArray)
append in class PrimitiveArrayprimitiveArray - primitiveArray must be the same or a narrower
data type, or the data will be narrowed with Math2.narrowToByte.public PrimitiveArray makeIndices(IntArray indices)
makeIndices in class PrimitiveArrayindices - the intArray that will capture the indices of the values
(ties get the same index). For example, 10,10,25,3 returns 1,1,2,0.
public int switchFromTo(java.lang.String tFrom,
java.lang.String tTo)
switchFromTo in class PrimitiveArraytFrom - the original value (use "" or "NaN" for standard missingValue)tTo - the new value (use "" or "NaN" for standard missingValue)
public java.lang.String isAscending()
isAscending in class PrimitiveArraypublic java.lang.String isDescending()
isDescending in class PrimitiveArraypublic int firstTie()
firstTie in class PrimitiveArraypublic java.lang.String isEvenlySpaced()
isEvenlySpaced in class PrimitiveArraypublic java.lang.String minValue()
minValue in class PrimitiveArraypublic java.lang.String maxValue()
maxValue in class PrimitiveArraypublic int[] getNMinMaxIndex()
getNMinMaxIndex in class PrimitiveArray
public static void test()
throws java.lang.Throwable
java.lang.Throwable - if trouble.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||