|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--uk.co.prosperosoftware.pspnum.PSPDecAr
PSPDecAr (short for 'Prospero Software Products Decimal Array')
is a class that records and manipulates arrays of decimal numbers with exact
precision. Each PSPDecAr has a declared Dimension (the number of elements in the
array). You set the current element of the PSPDecAr array via the
setElement() method.
The PSPDecAr class is based on the PSPDec
class which is included separately in our decimal numeric packages. In fact, PSPDecAr
encapsulates a single PSPDec object named 'Num' which always stores the value
of the current PSPDecAr element. 'Num' is declared with public access, so you can
invoke any PSPDec method on it directly e.g.
// Declare array 5 elements each 11 digits before decimal place and 2 digits
after decimal place
PSPDecAr MyArray = new PSPDecAr(11,2,5);
// Access current element of array - add 1 to it.
MyArray.Num.add("1");
The general rule is that operations on the PSPDec 'Num' object affect only that current element of the array, whereas operations on the entire PSPDecAr affect multiple elements of the array.
You can declare your own arrays/collections of PSPDec objects in Java. However using the PSPDecAr class is considerably more efficient and provides many more operations (such as sorting or summing elements) than a regular Java array of PSPDec objects could provide.
PSPDecAr/PSPDec classes are much better than floating-point to use for decimal numerics. PSPDecAr/PSPDec classes are quite similar to, but also better than the Java BigDecimal class.
Generally all issues for PSPDec arithmetic and logical operations such as
overflow and rounding
behaviour apply equally to PSPDecAr objects. For example, there are very similar
methods such as addRound for the two classes which treat rounding the same way.
The only difference is that PSPDecAr offers multiple element values to which these
operations may apply, wheras PSPDec is always limited to only one value.
All PSPDecAr elements have the same exact decimal size i.e. you set the number of digits you want either side of the decimal place. The internal numeric value(s) are exact (no degrees of precision) within these limits. You can access the value of one array element or the entire array via the internal packed decimal or zoned decimal formats, however you are more likely to access the numeric value(s) as a plain string or a string you can format via a mask.
Click here for index to PSPDecAr online documentation and some introductory Java code samples showing basic uses of PSPDecAr.
| Field Summary | |
static int |
MAXBASE
Maximum Base (first element number) allowed for any one PSPDecAr array via setBase(..) method. |
static int |
MAXDIMENSION
Maximum Dimension allowed for any one PSPDecAr array via setDimension(..) method. |
PSPDec |
Num
Encapsulated PSPDec object representing current element of PSPDecAr. |
| Constructor Summary | |
PSPDecAr(char format,
int digitsBeforeDP,
int digitsAfterDP,
int dimension)
Construct new PSPDecAr with specified format, number of digits either side of decimal place, and dimension. |
|
PSPDecAr(char format,
int digitsBeforeDP,
int digitsAfterDP,
int dimension,
PSPDec assignValue)
Construct new PSPDecAr with specified format, number of digits either side of decimal place, dimension and initial value same as parameter PSPDec. |
|
PSPDecAr(char format,
int digitsBeforeDP,
int digitsAfterDP,
int dimension,
java.lang.String assignValue)
Construct new PSPDecAr with specified format, number of digits either side of decimal place, dimension and initial numeric value(s) in parameter String. |
|
PSPDecAr(int digitsBeforeDP,
int digitsAfterDP,
int dimension)
Construct new PSPDecAr with specified number of digits either side of decimal place and dimension. |
|
PSPDecAr(int digitsBeforeDP,
int digitsAfterDP,
int dimension,
PSPDec assignValue)
Construct new PSPDecAr with number of digits either side of decimal place, dimension and initial value same as parameter PSPDec. |
|
PSPDecAr(int digitsBeforeDP,
int digitsAfterDP,
int dimension,
java.lang.String assignValue)
Construct new PSPDecAr with number of digits either side of decimal place, dimension and initial numeric value(s) in parameter String. |
|
PSPDecAr(PSPDecAr copyDecAr)
Construct new PSPDecAr with all attributes and value same as parameter PSPDecAr (copy constructor). |
|
| Method Summary | |
PSPDecAr |
add(PSPDec addValue)
Add value of parameter PSPDec to every element of this array (equivalent to the += operator) without rounding. |
PSPDecAr |
add(java.lang.String addValue)
Add single numeric value in paramater String to every element of this array (equivalent to the += operator) without rounding. |
PSPDecAr |
addRound(PSPDec addValue)
Add value of parameter PSPDec to every element of this array (equivalent to the += operator) with rounding. |
PSPDecAr |
addRound(java.lang.String addValue)
Add single numeric value in paramater String to every element of this array (equivalent to the += operator) with rounding. |
PSPDecAr |
assign(PSPDec assignValue)
Assign value of parameter PSPDec to every element of this array without rounding. |
PSPDecAr |
assign(java.lang.String assignValue)
Assign numeric value(s) in parameter String to elements of this array without rounding. |
PSPDecAr |
assign(java.lang.String assignValue,
char decimalPlace)
Assign numeric value(s) in parameter String to elements of this array without rounding. |
PSPDecAr |
assignRound(PSPDec assignValue)
Assign value of parameter PSPDec to every element of this array with rounding. |
PSPDecAr |
assignRound(java.lang.String assignValue)
Assign numeric value(s) in parameter String to elements of this array with rounding. |
PSPDecAr |
assignRound(java.lang.String assignValue,
char decimalPlace)
Assign numeric value(s) in parameter String to elements of this array with rounding. |
PSPDecAr |
clear()
Clear value of every element of array - set to zero. |
PSPDecAr |
divide(PSPDec that)
Divide every element of this array by value of parameter PSPDec (equivalent to the /= operator) without rounding. |
PSPDecAr |
divide(java.lang.String divideValue)
Divide every element of this array by single numeric value in parameter String (equivalent to the /= operator) without rounding. |
PSPDecAr |
divideRound(PSPDec divideValue)
Divide every element of this array by value of parameter PSPDec (equivalent to the /= operator) with rounding. |
PSPDecAr |
divideRound(java.lang.String divideValue)
Divide every element of this array by single numeric value in parameter String (equivalent to the /= operator) with rounding. |
int |
getBase()
Retrieve Base (index of lowest element) of this array. |
int |
getDigitsAfterDP()
Retrieve current setting for number of digits after decimal place (applies to every element of the array). |
int |
getDigitsBeforeDP()
Retrieve current setting for number of digits before decimal place (applies to every element of the array). |
int |
getDimension()
Retrieve Dimension (total number of elements) of this array. |
int |
getElement()
Retrieve current element (index) of this array. |
int |
getMaxElement()
Retrieve highest permissible element number (index) of this array. |
byte[] |
getPackedValue()
Retrieve numeric value of this entire array (all elements) in packed decimal format. |
byte[] |
getValue()
Retrieve numeric value of this entire array (all elements) in format (zoned or packed decimal) currently determined for the array by the Num.getFormat() method. |
int |
getValueLength()
Retrieve length of byte array that would be returned by getValue() method. |
byte[] |
getZonedValue()
Retrieve numeric value of this entire array (all elements) in zoned decimal format. |
boolean |
isEQ(PSPDec compareValue)
Test if every element of this array has numeric value same as parameter PSPDec. |
boolean |
isEQ(java.lang.String compareValue)
Test if every element of this array has value same as single numeric value in parameter string. |
boolean |
isGE(PSPDec compareValue)
Test if every element of this array has numeric value greater than or equal to parameter PSPDec. |
boolean |
isGE(java.lang.String rhs)
Test if every element of this array has value greater than or equal to single numeric value in parameter string. |
boolean |
isGT(PSPDec compareValue)
Test if every element of this array has numeric value greater than parameter PSPDec. |
boolean |
isGT(java.lang.String compareValue)
Test if every element of this array has value greater than single numeric value in parameter string. |
boolean |
isLE(PSPDec compareValue)
Test if every element of this array has numeric value less than or equal to parameter PSPDec. |
boolean |
isLE(java.lang.String compareValue)
Test if every element of this array has value less than or equal to single numeric value in parameter string. |
boolean |
isLT(PSPDec compareValue)
Test if every element of this array has numeric value less than parameter PSPDec. |
boolean |
isLT(java.lang.String compareValue)
Test if every element of this array has value less than single numeric value in parameter string. |
boolean |
isNE(PSPDec compareValue)
Test if every element of this array has numeric value not equal to parameter PSPDec. |
boolean |
isNE(java.lang.String compareValue)
Test if every element of this array has value not equal to single numeric value in parameter string. |
boolean |
isNegative()
Test if every element of this array has a negative value. |
boolean |
isPositive()
Test if every element of this array has a positive value. |
boolean |
isZero()
Test if every element of this array has a zero value. |
PSPDecAr |
multiply(PSPDec that)
Multiply every element of this array by value of parameter PSPDec (equivalent to the *= operator) without rounding. |
PSPDecAr |
multiply(java.lang.String that)
Multiply every element of this array by single numeric value in parameter String (equivalent to the *= operator) without rounding. |
PSPDecAr |
multiplyRound(PSPDec that)
Multiply every element of this array by value of parameter PSPDec (equivalent to the *= operator) with rounding. |
PSPDecAr |
multiplyRound(java.lang.String that)
Multiply every element of this array by single numeric value in parameter String (equivalent to the *= operator) with rounding. |
int |
setBase(int Base)
Set Base (index of lowest element) of this array. |
int |
setDigitsAfterDP(int digitsAfterDP)
Reset number of digits after the decimal place for this array, without rounding if digits reduced. |
int |
setDigitsAfterDPRound(int digitsAfterDP)
Reset number of digits after the decimal place for this array, with rounding if digits reduced. |
int |
setDigitsBeforeDP(int digitsBeforeDP)
Reset number of digits before decimal place for this array, with treatment of overflow determined by Num.getOverflow() if digits reduced. |
int |
setDimension(int d)
Reset Dimension (total number of elements) of this array. |
int |
setElement(int idx)
Set current element (index) of this array. |
PSPDecAr |
setHighValue()
Set numeric value of every element of this array to highest possible value - every digit set to 9 and positive value assigned. |
PSPDecAr |
setLowValue()
Set numeric value of every element of this array to lowest possible value - every digit set to 9 and negative value assigned. |
PSPDecAr |
sortAscend()
Sort elements of this array into ascending sequence by numeric value. |
PSPDecAr |
sortAscend(boolean preserveElement)
Sort elements of this array into ascending sequence by numeric value. |
PSPDecAr |
sortDescend()
Sort elements of this array into descending sequence by numeric value. |
PSPDecAr |
sortDescend(boolean preserveElement)
Sort elements of this array into descending sequence by numeric value. |
PSPDecAr |
subtract(PSPDec subtractValue)
Subtract value of parameter PSPDec from every element of this array (equivalent to the -= operator) without rounding. |
PSPDecAr |
subtract(java.lang.String subtractValue)
Subtract single numeric value in parameter String from every element of this array (equivalent to the -= operator) without rounding. |
PSPDecAr |
subtractRound(PSPDec subtractValue)
Subtract value of parameter PSPDec from every element of this array (equivalent to the -= operator) with rounding. |
PSPDecAr |
subtractRound(java.lang.String subtractValue)
Subtract single numeric value in parameter String from every element of this array (equivalent to the -= operator) with rounding. |
java.lang.String |
sumElements()
Total element values of this array and return the sum as a plain formatted String with the decimal place (if any) given by the Num.getDecimalPlace() method. |
java.lang.String |
toString()
Returns the internal numeric value of all array elements of this array in a String where element values 1) are delimited by ';' and 2) use the decimal place (if any) given by the Num.getDecimalPlace()
method. |
java.lang.String |
toString(char DecimalPlace)
Returns the internal numeric value of all array elements of this array in a String where element values are 1) delimited by ';' and 2) use the decimal place (if any) specified via parameter. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int MAXDIMENSION
setDimension(..) method. Value is 2000.
public static final int MAXBASE
setBase(..) method. Value is 20000.
public PSPDec Num
| Constructor Detail |
public PSPDecAr(char format,
int digitsBeforeDP,
int digitsAfterDP,
int dimension)
throws PSPException
format - of internal value - 'P' for packed decimal, 'Z' for zoned decimal.digitsBeforeDP - for number of digits before decimal place.digitsAfterDP - for number of digits after decimal place.dimension - number of array elemnents.
public PSPDecAr(char format,
int digitsBeforeDP,
int digitsAfterDP,
int dimension,
PSPDec assignValue)
throws PSPException
format - of internal value - 'P' for packed decimal, 'Z' for zoned decimal.digitsBeforeDP - for number of digits before decimal place.digitsAfterDP - for number of digits after decimal place.dimension - number of array elemnents.assignValue - initial value assigned to *every* element of array.
public PSPDecAr(char format,
int digitsBeforeDP,
int digitsAfterDP,
int dimension,
java.lang.String assignValue)
throws PSPException
format - of internal value - 'P' for packed decimal, 'Z' for zoned decimal.digitsBeforeDP - for number of digits before decimal place.digitsAfterDP - for number of digits after decimal place.dimension - number of array elements.assignValue - initial value assigned to *every* element of array (if
a single value) otherwise to elements of array from first (if multiple
values delimited by ';').
public PSPDecAr(int digitsBeforeDP,
int digitsAfterDP,
int dimension)
throws PSPException
digitsBeforeDP - for number of digits before decimal place.digitsAfterDP - for number of digits after decimal place.dimension - number of array elements.
public PSPDecAr(int digitsBeforeDP,
int digitsAfterDP,
int dimension,
PSPDec assignValue)
throws PSPException
digitsBeforeDP - for number of digits before decimal place.digitsAfterDP - for number of digits after decimal place.dimension - number of array elements.assignValue - initial value assigned to *every* element of array.
public PSPDecAr(int digitsBeforeDP,
int digitsAfterDP,
int dimension,
java.lang.String assignValue)
throws PSPException
digitsBeforeDP - for number of digits before decimal place.digitsAfterDP - for number of digits after decimal place.dimension - number of array elements.assignValue - initial value assigned to *every* element of array (if
a single value) otherwise to elements of array from first (if multiple
values delimited by ';').
public PSPDecAr(PSPDecAr copyDecAr)
throws PSPException
copyDecAr - the PSPDecAr to be copied.| Method Detail |
public PSPDecAr add(PSPDec addValue)
throws PSPException
addValue - value to be added to every element of this array.
PSPException
public PSPDecAr add(java.lang.String addValue)
throws PSPException
addValue - value to be added to every element of this array.
PSPException
public PSPDecAr addRound(PSPDec addValue)
throws PSPException
addValue - value to be added to every element of this array.
PSPException
public PSPDecAr addRound(java.lang.String addValue)
throws PSPException
addValue - value to be added to every element of this array.
PSPException
public PSPDecAr assign(PSPDec assignValue)
throws PSPException
assignValue - value to be assigned to every element of this array.
PSPException
public PSPDecAr assign(java.lang.String assignValue)
throws PSPException
Num.getDecimalPlace() method.
assignValue - value assigned to every element of array (if
a single value) otherwise to elements of array from first
(if multiple values delimited by ';').
PSPException
public PSPDecAr assign(java.lang.String assignValue,
char decimalPlace)
throws PSPException
assignValue - value assigned to every element of array (if
a single value) otherwise to elements of array from first
(if multiple values delimited by ';').decimalPlace - the character used for the decimal place in the String.
PSPException
public PSPDecAr assignRound(PSPDec assignValue)
throws PSPException
assignValue - value to be assigned to every element of this array.
PSPException
public PSPDecAr assignRound(java.lang.String assignValue)
throws PSPException
Num.getDecimalPlace() method.
assignValue - value assigned to *every* element of array (if
a single value) otherwise to elements of array from first
(if multiple values delimited by ';').
PSPException
public PSPDecAr assignRound(java.lang.String assignValue,
char decimalPlace)
throws PSPException
assignValue - value assigned to every element of array (if
a single value) otherwise to elements of array from first
(if multiple values delimited by ';').decimalPlace - the character used for the decimal place in the String.
PSPException
public PSPDecAr clear()
throws PSPException
PSPException
public PSPDecAr divide(PSPDec that)
throws PSPException
PSPException
public PSPDecAr divide(java.lang.String divideValue)
throws PSPException
divideValue - value to be divided into every element of this array.
PSPException
public PSPDecAr divideRound(PSPDec divideValue)
throws PSPException
divideValue - value to be divided into every element of this array.
PSPException
public PSPDecAr divideRound(java.lang.String divideValue)
throws PSPException
divideValue - value to be divided into every element of this array.
PSPExceptionpublic int getBase()
public int getDimension()
public int getDigitsAfterDP()
public int getDigitsBeforeDP()
public int getElement()
public int getMaxElement()
public byte[] getPackedValue()
throws PSPException
PSPException
public byte[] getValue()
throws PSPException
Num.getFormat() method.
PSPExceptionpublic int getValueLength()
getValue() method.
getValue() method.
public byte[] getZonedValue()
throws PSPException
PSPException
public boolean isEQ(PSPDec compareValue)
throws PSPException
compareValue - PSPDec with value to be compared.
PSPException
public boolean isEQ(java.lang.String compareValue)
throws PSPException
compareValue - String holding single numeric value to be compared.
PSPException
public boolean isGE(PSPDec compareValue)
throws PSPException
compareValue - PSPDec with value to be compared.
PSPException
public boolean isGE(java.lang.String rhs)
throws PSPException
PSPException
public boolean isGT(PSPDec compareValue)
throws PSPException
compareValue - PSPDec with value to be compared.
PSPException
public boolean isGT(java.lang.String compareValue)
throws PSPException
compareValue - String holding single numeric value to be compared.
PSPException
public boolean isLE(PSPDec compareValue)
throws PSPException
compareValue - PSPDec with value to be compared.
PSPException
public boolean isLE(java.lang.String compareValue)
throws PSPException
compareValue - String holding single numeric value to be compared.
PSPException
public boolean isLT(PSPDec compareValue)
throws PSPException
compareValue - PSPDec with value to be compared.
PSPException
public boolean isLT(java.lang.String compareValue)
throws PSPException
compareValue - String holding single numeric value to be compared.
PSPException
public boolean isNE(PSPDec compareValue)
throws PSPException
compareValue - PSPDec with value to be compared.
PSPException
public boolean isNE(java.lang.String compareValue)
throws PSPException
compareValue - PSPDec with value to be compared.
PSPExceptionpublic boolean isNegative()
public boolean isPositive()
public boolean isZero()
public PSPDecAr multiply(PSPDec that)
throws PSPException
PSPException
public PSPDecAr multiply(java.lang.String that)
throws PSPException
PSPException
public PSPDecAr multiplyRound(PSPDec that)
throws PSPException
PSPException
public PSPDecAr multiplyRound(java.lang.String that)
throws PSPException
PSPExceptionpublic int setBase(int Base)
getElement() is adjusted by the difference
between the old/new bases so as to index the same element
in the array before/after the Base is changed.
Base - new Base for array.
public int setDigitsAfterDP(int digitsAfterDP)
digitsAfterDP - the new number of digits after the decimal place.
public int setDigitsAfterDPRound(int digitsAfterDP)
digitsAfterDP - the new number of digits after the decimal place.
public int setDigitsBeforeDP(int digitsBeforeDP)
Num.getOverflow() if digits reduced.
The new setting applies to every element of the array.
digitsBeforeDP - the new number of digits before the decimal place.
public int setDimension(int d)
getElement() may be
reduced if it previously indexed an element in the reduced portion of the
array. In this case, the new current element is simply the last in the array.
public int setElement(int idx)
getBase() and
getMaxElement().
When you do this, the new element value is automatically
refreshed in the PSPDec named 'Num' encapsulated within
this PSPDecAr.
public PSPDecAr setHighValue()
throws PSPException
PSPException
public PSPDecAr setLowValue()
throws PSPException
PSPException
public PSPDecAr sortAscend()
throws PSPException
getElement() of the array is unchanged,
so the encapsulated PSPDec 'Num' may have a different numeric value
after the sort.
PSPException
public PSPDecAr sortAscend(boolean preserveElement)
throws PSPException
getElement() of the array
may change or not, depending upon your boolean choice for
the single parameter to this method. If 'false' then the
current element does not change in which case the encapsulated
PSPDec 'Num' may have a different numeric value after the sort.
If 'true', then the current element changes so that it indexes
the same numeric value in the array before/after the sort -
the encapsulated PSPDec 'Num' holds the same numeric value
after the sort as before.
preserveElement - if current element of array is to index
same numeric value before and after the sort -
getElement() is allowed to adjust.
PSPException
public PSPDecAr sortDescend()
throws PSPException
getElement() of the array
is unchanged, so the encapsulated PSPDec 'Num' may have
a different numeric value after the sort.
PSPException
public PSPDecAr sortDescend(boolean preserveElement)
throws PSPException
getElement() of the array
may change or not, depending upon your boolean choice for
the single parameter to this method. If 'false' then the
current element does not change in which case the encapsulated
PSPDec 'Num' may have a different numeric value after the sort.
If 'true', then the current element changes so that it indexes
the same numeric value in the array before/after the sort so
the encapsulated PSPDec 'Num' holds the same numeric value
after the sort as before.
preserveElement - if current element of array is to index
same numeric value before and after the sort -
getElement() is allowed to adjust.
PSPException
public PSPDecAr subtract(PSPDec subtractValue)
throws PSPException
subtractValue - value to be subtracted from every element of this array.
PSPException
public PSPDecAr subtract(java.lang.String subtractValue)
throws PSPException
subtractValue - value to be subtracted from every element of this array.
PSPException
public PSPDecAr subtractRound(PSPDec subtractValue)
throws PSPException
subtractValue - value to be subtracted from every element of this array.
PSPException
public PSPDecAr subtractRound(java.lang.String subtractValue)
throws PSPException
subtractValue - value to be subtracted from every element of this array.
PSPException
public java.lang.String sumElements()
throws PSPException
Num.getDecimalPlace() method.
PSPException
public java.lang.String toString()
throws PSPException
Num.getDecimalPlace()
method.
toString in class java.lang.ObjectPSPException
public java.lang.String toString(char DecimalPlace)
throws PSPException
PSPException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||