Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class ncsa.horizon.util.IntLikeDblArray

java.lang.Object
  |
  +--ncsa.horizon.util.IntLikeDblArray

public class IntLikeDblArray
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
an object representing an array of mutable floating point numbers restricted to the range of a Java integer.

This is useful for holding array values that are usually accessed as integer values, but can have fractional values. Methods for getting and setting the values are made final for efficient and fast access. The storage is optimized for integer access by storing the integer part of the value separately from the fractional part. How the floating point value is converted to an integer can be set via the setConversionMode(), allowing 3 possible modes: ROUND, CEILING, and FLOOR. The changing the mode changes how the values are stored, optimizing for the requested conversion. The ROUND mode simply rounds the value to the nearest integer in the usual way (equivalent to Math.round()). FLOOR will convert the value to the greatest integer that is less than or equal to the value. CEILING will convert to the smallest integer that is greater than or equal to the value. (In all cases, "smaller" means more negative, and "larger" more positive.)

See Also:
Serialized Form

Field Summary
static byte CEILING
          the "ceiling-ing" conversion mode.
static byte FLOOR
          the "flooring" conversion mode.
static int MAX_VALUE
          the largest value an array element can hold.
static int MIN_VALUE
          the smallest value an array element can hold.
static byte ROUND
          the rounding conversion mode.
 
Constructor Summary
IntLikeDblArray(int n, byte mode)
          create an array of a requested length and conversion mode.
IntLikeDblArray(int n)
          create an array of a requested length.
IntLikeDblArray(int n, byte mode, int val)
          create an array of a requested length and conversion mode.
IntLikeDblArray(int n, byte mode, double val)
          create an array of a requested length and conversion mode.
 
Method Summary
void addDbl(int idx, double val)
          add a floating point amount to the value at a given index
void addDbl(int idx, int i, float f)
          add a floating point amount to the value at a given index.
void addInt(int idx, int val)
          add an integer amount to the value at a given index
void add(int idx, IntLikeDblArray val)
          add the value at a given index in another IntLikeDblArray to the corresponding value in this one.
void clearZeroFrac()
          eliminate fractional components if they are all equal to zero.
java.lang.Object clone()
           
java.io.DataOutput dataOut(java.io.DataOutput dout)
          write out our data to the data output.
boolean equals(IntLikeDblArray that)
           
byte[] getConversionMode()
          return the current conversion mode for each array element
byte getConversionMode(int idx)
          return the current conversion mode for a given element
double[] getDbl()
          return the values as an array of doubles
double getDbl(int i)
          return the value at a given index.
int[] getInt()
          return the values as an array of integers
int getInt(int i)
          return the value at a given index.
int[] getIntRef()
          return the values via a reference to an array of integers.
int getLength()
          return the length of the array (same as length()).
boolean isFractional(int idx)
          return true if the value at a given index has a fractional component
int length()
          return the length of the array (same as getLength()).
void setConversionMode(int idx, byte cmode)
          set the current conversion mode for a given array element
void setConversionMode(byte cmode)
          set the current conversion mode for all array element to the same mode
void setConversionMode(byte[] cmode)
          set the current conversion mode for all array element to the same mode
void setDbl(double[] val)
          set the values to those in a given array of doubles
void setDbl(int idx, double val)
          set the value at a given index.
void setDbl(int idx, int whole, float fract)
          set a component the position to the value given by the double value given by the input integer and float.
void setInt(int[] val)
          set the values to those in a given array of integers
void setInt(int idx, int val)
          set the value at a given index
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final int MAX_VALUE
the largest value an array element can hold. This is equal to Integer.MAX_VALUE.

MIN_VALUE

public static final int MIN_VALUE
the smallest value an array element can hold. This is equal to Integer.MIN_VALUE.

ROUND

public static final byte ROUND
the rounding conversion mode. In this mode, the floating point values will be converted when necessary by rounding them to the nearest integer.

FLOOR

public static final byte FLOOR
the "flooring" conversion mode. In this mode, the floating point values will be converted when necessary by setting them to the greatest integer that is less than or equal to the value.

CEILING

public static final byte CEILING
the "ceiling-ing" conversion mode. In this mode, the floating point values will be converted when necessary by setting them to the smallest integer that is greater than or equal to the value.
Constructor Detail

IntLikeDblArray

public IntLikeDblArray(int n,
                       byte mode)
                throws ValueOutOfBoundsException
create an array of a requested length and conversion mode. The initial array values will be 0.0.
Throws:
ValueOutOfBoundsException - if mode is not recoginized

IntLikeDblArray

public IntLikeDblArray(int n)
create an array of a requested length. The default conversion mode will be ROUND, and the initial array values will be 0.0.

IntLikeDblArray

public IntLikeDblArray(int n,
                       byte mode,
                       int val)
                throws ValueOutOfBoundsException
create an array of a requested length and conversion mode. The initial array values will be a given value
Parameters:
n - the number of array elements
mode - the conversion mode to use
val - the value to assign to each element
Throws:
ValueOutOfBoundsException - if mode is not recoginized or n is negative

IntLikeDblArray

public IntLikeDblArray(int n,
                       byte mode,
                       double val)
                throws ValueOutOfBoundsException
create an array of a requested length and conversion mode. The initial array values will be a given value
Parameters:
n - the number of array elements
mode - the conversion mode to use
val - the value to assign to each element
Throws:
ValueOutOfBoundsException - if mode is not recoginized, n is negative, or val is out of bounds.
Method Detail

length

public final int length()
return the length of the array (same as getLength()).

getLength

public final int getLength()
return the length of the array (same as length()).

getConversionMode

public final byte[] getConversionMode()
return the current conversion mode for each array element

getConversionMode

public final byte getConversionMode(int idx)
return the current conversion mode for a given element

setConversionMode

public final void setConversionMode(int idx,
                                    byte cmode)
                            throws ValueOutOfBoundsException
set the current conversion mode for a given array element
Throws:
ValueOutOfBoundsException - if mode is not recoginized

setConversionMode

public final void setConversionMode(byte cmode)
                            throws ValueOutOfBoundsException
set the current conversion mode for all array element to the same mode
Throws:
ValueOutOfBoundsException - if mode is not recoginized

setConversionMode

public final void setConversionMode(byte[] cmode)
                            throws ValueOutOfBoundsException
set the current conversion mode for all array element to the same mode
Throws:
ValueOutOfBoundsException - if mode is not recoginized

getInt

public final int[] getInt()
return the values as an array of integers

getIntRef

public final int[] getIntRef()
return the values via a reference to an array of integers. This method is faster than getInt() but gives access to internal data. Callers of this method should use the result for read-only purposes.

getInt

public final int getInt(int i)
return the value at a given index.

setInt

public final void setInt(int[] val)
set the values to those in a given array of integers

setInt

public final void setInt(int idx,
                         int val)
set the value at a given index

addInt

public final void addInt(int idx,
                         int val)
add an integer amount to the value at a given index

getDbl

public final double[] getDbl()
return the values as an array of doubles

getDbl

public final double getDbl(int i)
return the value at a given index.

setDbl

public final void setDbl(double[] val)
                 throws ValueOutOfBoundsException
set the values to those in a given array of doubles

setDbl

public final void setDbl(int idx,
                         double val)
                 throws ValueOutOfBoundsException
set the value at a given index.

addDbl

public final void addDbl(int idx,
                         double val)
add a floating point amount to the value at a given index

add

public void add(int idx,
                IntLikeDblArray val)
add the value at a given index in another IntLikeDblArray to the corresponding value in this one.

addDbl

protected void addDbl(int idx,
                      int i,
                      float f)
add a floating point amount to the value at a given index. The amount to add is the sub of a given integer and float value.
Parameters:
whole - the integer part of the value
fract - the fractional part of the value

setDbl

protected void setDbl(int idx,
                      int whole,
                      float fract)
set a component the position to the value given by the double value given by the input integer and float.
Parameters:
whole - the integer part of the value
fract - the fractional part of the value

clearZeroFrac

public final void clearZeroFrac()
eliminate fractional components if they are all equal to zero. This can make the value access more efficient. This method is not usually called directly by applications.

isFractional

public boolean isFractional(int idx)
return true if the value at a given index has a fractional component

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

equals

public boolean equals(IntLikeDblArray that)

dataOut

public java.io.DataOutput dataOut(java.io.DataOutput dout)
                          throws java.io.IOException
write out our data to the data output. This is not usually called by most clients.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD