public class Decimal
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
dec_dgts
Array of base 100 digits (2 per byte)
|
protected short |
dec_exp
Exponent in base 100
|
protected short |
dec_ndgts
Base 100 digits
|
protected short |
dec_pos
Sign.
|
static int |
DEC_T_SIZE
number of bytes in a C dec_t struct
sizeof(short) * 3 + DECSIZE = 22
|
static short |
DECPOSNEGATIVE
indicates NEGATIVE decimal number
|
static short |
DECPOSNULL
indicates NULL decimal number
|
static short |
DECPOSPOSITIVE
indicates POSITIVE decimal number
|
static int |
DECSIZE
number of bytes allocated for IFX DECIMAL
|
static java.lang.String |
digChar |
protected byte |
endCode
endCode is the end DateTime code as received from IFX
Only relevent when timestamp = true
|
protected int |
lenOfFirstField |
protected byte |
pdigs
Total significant digits.
|
protected short |
precStored |
protected byte |
pscale
Scale, i.e., digits after decimal point
|
protected byte |
startCode
startCode is the start DateTime code as received from IFX
Only relevent when timestamp = true
|
protected boolean |
timestamp
Set to true when this represents a DateTime as opposed to Bignum
This is needed so scale can be correctly interpreted since scale encodes
totally different info in the two cases.
|
static byte |
TU_DAY |
static java.util.Hashtable<java.lang.Integer,java.lang.Integer> |
TU_Exp_Table |
static byte |
TU_F1 |
static byte |
TU_F2 |
static byte |
TU_F3 |
static byte |
TU_F4 |
static byte |
TU_F5 |
static byte |
TU_FRAC |
static byte |
TU_HOUR |
static byte |
TU_MINUTE |
static byte |
TU_MONTH |
static byte |
TU_SECOND |
static byte |
TU_YEAR |
| Constructor and Description |
|---|
Decimal()
Null Decimal constructor
Dont need to fill any fields since default fields are
for a NULL decimal
|
Decimal(java.math.BigDecimal n)
Constructs a Decimal given a java.lang.Bignum
Unfortunately, Bignum does NOT provide access to its data members
so we have to take the roundabout way of converting to string.
|
Decimal(boolean sign,
byte[] b,
int blen,
short inPrec) |
Decimal(byte[] cp)
For debugging only
Unlike the other constructors,
this one expects bytes[0,1] to contain the length of the remaining bytes.
|
Decimal(byte[] cp,
int offset,
int length,
short prec)
Converts bytes as received from IFX server into a Decimal obj
|
Decimal(byte[] cp,
int offset,
int length,
short prec,
boolean ts)
Converts bytes as received from IFX server into a Decimal obj but
interpreted as a timestamp data
|
Decimal(byte[] cp,
short prec)
Converts bytes as received from IFX server into a Decimal obj
|
Decimal(byte[] cp,
short prec,
boolean ts)
Converts bytes as received from IFX server into a Decimal obj but
interpreted as a timestamp data
|
Decimal(IfxDateTime dateTime) |
Decimal(int yyyy,
int mo,
int dd,
int hh,
int mm,
int ss,
int fffff) |
Decimal(short exp,
short pos,
short ndgts,
byte[] d)
Constructor given basic fields as separate arg
|
Decimal(java.lang.String num)
Creates Decimal from a string form of a decimal number
of the form created by Bignum or by hand.
|
Decimal(java.lang.String num,
short inPrec) |
| Modifier and Type | Method and Description |
|---|---|
static void |
bycopy(byte[] from,
int fromStart,
byte[] to,
int toStart)
Copies bytes (or as many will fit) of first array
into second starting with the fromStart pos.
|
static byte[] |
byfill(byte[] b,
byte f)
Fills given byte array with the given fill byte
|
static void |
charcopy(char[] from,
int fromStart,
int fromEnd,
char[] to,
int toStart)
Copies all chars (or as many will fit) of first array
into second starting with fromStart upto fromEnd (both incl)
It is expected that to.length - toStart >= fromEnd - fromStart+1
|
static char[] |
charfill(char[] b,
int from,
int to,
char f)
Fills given char array (from -> to, both incl) with the given fill char
|
protected void |
computePrecision() |
protected void |
computeScale() |
static Decimal |
dec_tToJava(byte[] b) |
static byte[] |
decComplement(byte[] b,
int start)
Takes 100s complement of the given byte array
starting from the end, backwards upto the "start" byte
Process: byte[n] = 100- byte[n]
byte[0] ..
|
java.lang.Double |
doubleValue()
Returns a Double equivalent of this.
|
static byte[] |
encodeDateTimePrecision(byte[] b,
byte s,
byte e)
Encodes precision for Datetime for transmission to IFX
See the macro TU_DTENCODE in the IFX file datetime.h
|
static byte[] |
encodeIntervalPrecision(byte[] b,
byte len,
byte s,
byte e)
Encodes precision for interval for transmission to IFX
See the macro TU_IENCODE in the IFX file datetime.h
|
protected int |
extractExponent(java.lang.String num,
int start)
Given number string checks if it contains an exponent
checking from start char.
|
java.lang.Float |
floatValue()
Returns a Float equivalent of this.
|
static byte[] |
fromBindToTuple(byte[] bindFormat,
int newLength) |
byte[] |
getPrecision()
Returns the precision as a 2-byte array
|
protected void |
init(byte[] cp,
int offset,
int length,
short prec)
Given a packed byte array of the form received from IFX servers
creates Decimal.
|
Interval |
intervalValue() |
boolean |
isNull() |
byte[] |
javaToDec_t()
Convert Decimal to byte array that's in Informix dec_t format as
defined in decimal.h.
|
byte[] |
javaToIfx()
Converts Decimal to byte array for sending out to IFX servers
The format of the bytes is as follows:
b[0], b[1] - length of bytes from b[2] on
b[2] ..
|
static Decimal |
numericToDecimal(java.math.BigDecimal n)
Converts given Bignum to Decimal
|
java.math.BigDecimal |
numericValue()
Converts this to a Bignum with sufficient precision
and scale equal to whatever is needed based on the value of this
|
void |
setT() |
void |
setTimestampQualifier(short qualifier) |
char[] |
sigdigToChar()
Converts significant digits of this (base 100) to a char[]
Shouldnt be called if there are no significant digits
|
int |
sigdigToInt(int from,
int to)
Converts specified digits of this (base 100) to an int
|
java.lang.String |
stringValue()
Creates a string representing the decimal value in a form
that can be used to create an equivalent Bignum
If NULL returns an empty string
TBD ??? Use scale to pad with extra zeros to right if needed
|
java.sql.Timestamp |
timestampValue()
Interprets this as a DateTime that was encoded as a decimal
by IFX and returns a java.sql.Timestamp.
|
java.sql.Timestamp |
timestampValue(java.util.Calendar cal) |
protected static char[] |
trimZerosFB(char[] ibuf,
int start)
Given char array of digits and starting position
returns a new array with leading and trailing zeros stripped out
Leaves 0th element of returned array empty for sign
|
static byte |
tuEnd(byte c) |
static int |
tuFLen(short len) |
static byte |
tuLen(short c) |
static byte |
tuStart(byte c) |
void |
unpackPrecision(short prec)
Interprets prec to extract:
pdigs - precision, i.e., total digits
pscale - scale, i.e., digits after decimal pt to retain
Note: Interprets low byte depending on whether timestamp flg is set
If timestamp, then uses low 4 bits of low byte as end time indicator
(@see #TU_YEAR etc) and computes scale from that.
|
public static final java.lang.String digChar
public static final int DEC_T_SIZE
public static final int DECSIZE
public static final short DECPOSNULL
public static final short DECPOSPOSITIVE
public static final short DECPOSNEGATIVE
protected short dec_exp
protected short dec_pos
protected short dec_ndgts
protected byte[] dec_dgts
protected int lenOfFirstField
protected short precStored
protected byte pdigs
dec_ndgtsprotected byte pscale
protected boolean timestamp
protected byte startCode
protected byte endCode
public static final byte TU_YEAR
public static final byte TU_MONTH
public static final byte TU_DAY
public static final byte TU_HOUR
public static final byte TU_MINUTE
public static final byte TU_SECOND
public static final byte TU_FRAC
public static final byte TU_F1
public static final byte TU_F2
public static final byte TU_F3
public static final byte TU_F4
public static final byte TU_F5
public static java.util.Hashtable<java.lang.Integer,java.lang.Integer> TU_Exp_Table
public Decimal()
public Decimal(short exp,
short pos,
short ndgts,
byte[] d)
exp - base 100 exponentpos - sign (1 pos, 0, neg, -1 null)ndgts - base 100 digitsd - array of digits packed 2 per bytepublic Decimal(byte[] cp)
public Decimal(byte[] cp,
short prec)
cp - should contain only the data bytesprec - precisionpublic Decimal(byte[] cp,
int offset,
int length,
short prec)
cp - byte array containing a decimal in network formatoffset - offset into array where decimal data beginslength - length of decimal data in byte arrayprec - precisionpublic Decimal(byte[] cp,
short prec,
boolean ts)
cp - should contain only the data bytesprec - precisionts - if true then interped as timestamp. default is falsepublic Decimal(byte[] cp,
int offset,
int length,
short prec,
boolean ts)
cp - should contain only the data bytesoffset - offset into cp byte arraylength - length of dataprec - precisionts - if true then interped as timestamp. default is falsepublic Decimal(java.lang.String num)
string - the string from which Decimal is created
Format of input string:
Optional sign in first place.
Optional decimal pt anywhere
Optional exponent of the form "e+-nnn" at end. However,
if exponent is given then a decimal pt must precede it
somewhere in the number. Thus, "123e-034" is invalid.
This format is based on the one apparently used by java floats.
No other chars allowed. Dont add spaces either!!public Decimal(java.lang.String num,
short inPrec)
public Decimal(java.math.BigDecimal n)
n - Bignum from which equivalent Decimal is createdpublic Decimal(boolean sign,
byte[] b,
int blen,
short inPrec)
public Decimal(int yyyy,
int mo,
int dd,
int hh,
int mm,
int ss,
int fffff)
public Decimal(IfxDateTime dateTime)
public final void setTimestampQualifier(short qualifier)
public final void setT()
public final void unpackPrecision(short prec)
protected void computePrecision()
protected void computeScale()
public byte[] getPrecision()
protected void init(byte[] cp,
int offset,
int length,
short prec)
cp - byte[0] - contains the exponent in an encoded form
rest of the bytes - packed digits in the number (base 100)prec - encoded information about the precision of the decimal
with b[0] - precision and b[1] - scale
if prec =0 then uses the precision inherent in the numberprotected int extractExponent(java.lang.String num,
int start)
num - number as a string which may have an exponentstart - position where to start looking in stringpublic static byte[] byfill(byte[] b,
byte f)
public static char[] charfill(char[] b,
int from,
int to,
char f)
b - array to fillfrom - index of first position to fillto - index of last position to fillf - fill characterpublic static void bycopy(byte[] from,
int fromStart,
byte[] to,
int toStart)
from - source arrayfromStart - index of first byte copiedto - target arraytoStart - index of first recipient location in topublic static void charcopy(char[] from,
int fromStart,
int fromEnd,
char[] to,
int toStart)
from - source arrayfromStart - index of first char copiedfromEnd - index of last char copiedto - target arraytoStart - index of first recipient location in topublic static byte[] decComplement(byte[] b,
int start)
b - array of bytes packed with base 100 digitsstart - index of first byte to complementpublic byte[] javaToIfx()
public byte[] javaToDec_t()
public static Decimal dec_tToJava(byte[] b)
public char[] sigdigToChar()
public int sigdigToInt(int from,
int to)
from - first base 100 digitto - last base 100 digitpublic java.math.BigDecimal numericValue()
public boolean isNull()
public final java.lang.Double doubleValue()
public final java.lang.Float floatValue()
public java.lang.String stringValue()
protected static char[] trimZerosFB(char[] ibuf,
int start)
public static byte[] fromBindToTuple(byte[] bindFormat,
int newLength)
public static byte tuEnd(byte c)
public static byte tuStart(byte c)
public static byte tuLen(short c)
public static byte[] encodeDateTimePrecision(byte[] b,
byte s,
byte e)
public static byte[] encodeIntervalPrecision(byte[] b,
byte len,
byte s,
byte e)
public static int tuFLen(short len)
public java.sql.Timestamp timestampValue()
public java.sql.Timestamp timestampValue(java.util.Calendar cal)
public Interval intervalValue()
public static Decimal numericToDecimal(java.math.BigDecimal n)