uk.co.prosperosoftware.pspnum
Class PSPDec

java.lang.Object
  |
  +--uk.co.prosperosoftware.pspnum.PSPDec
All Implemented Interfaces:
java.io.Serializable

public class PSPDec
extends java.lang.Object
implements java.io.Serializable

PSPDec (short for 'Prospero Software Products Decimal') is a class that records and manipulates decimal numbers with exact precision. PSPDec is significantly better than floating-point for decimal numbers. PSPDec is quite similar to, but also better than the Java BigDecimal class.

Each PSPDec has an exact decimal size i.e. you set the number of digits you want either side of the decimal place. The internal numeric value is exact (no degrees of precision) within these limits. You can access the value via the internal packed decimal or zoned decimal formats, however you are more likely to access the numeric value as a plain string or a string you can format via a mask.

PSPDec supports a number of common arithmetic and logical operations for which you can specify both overflow and rounding behaviour.

Click here for index to PSPDec online documentation and some introductory Java code samples showing basic uses of PSPDec.

Version:
4.4 05Jun2003
Author:
www.prosperosoftware.co.uk
See Also:
Serialized Form

Field Summary
static int MAX_DIGITS
          Maximum number (100) of digits in total (before and after decimal place) for PSPDec.
static int MAX_DIGITS_AFTER
          Maximum number (50) of digits after decimal place for PSPDec.
static int MAX_DIGITS_BEFORE
          Maximum number (50) of digits before decimal place for PSPDec.
static byte OVERFLOW_BUMP_BEFOREDP
          When overflow occurs, PSPDec automatically increments DigitsBeforeDP to accommodate the new value.
static byte OVERFLOW_EXCEPTION
          When overflow occurs, PSPDec throws a PSPException error for which getErrNum() returns PSPException.NumOverflow.
static byte OVERFLOW_IGNORE
          When overflow occurs, PSPDec silently ignores the new value.
static byte OVERFLOW_IGNORE_BEEP
          When overflow occurs, PSPDec ignores the new value and beeps.
static byte OVERFLOW_TRUNCATE
          When overflow occurs, PSPDec silently truncates excess high-order digits.
static byte OVERFLOW_TRUNCATE_BEEP
          When overflow occurs, PSPDec truncates excess high-order digits and beeps.
 
Constructor Summary
PSPDec(char format, int digitsBeforeDP, int digitsAfterDP)
          Construct new PSPDec with specified format and number of digits either side of decimal place.
PSPDec(char format, int digitsBeforeDP, int digitsAfterDP, PSPDec assignValue)
          Construct new PSPDec with specified format, number of digits either side of decimal place and initial value given by parameter PSPDec.
PSPDec(char format, int digitsBeforeDP, int digitsAfterDP, java.lang.String assignValue)
          Construct new PSPDec with specified format, number of digits either side of decimal place and initial numeric value in parameter String.
PSPDec(int digitsBeforeDP, int digitsAfterDP)
          Construct new PSPDec with default format and number of digits either side of decimal place.
PSPDec(int digitsBeforeDP, int digitsAfterDP, PSPDec assignValue)
          Construct new PSPDec with default format, number of digits either side of decimal place and initial value given by parameter PSPDec.
PSPDec(int digitsBeforeDP, int digitsAfterDP, java.lang.String assignValue)
          Construct new PSPDec with default format, number of digits either side of decimal place and initial numeric value in parameter String.
PSPDec(PSPDec copyDec)
          Construct new PSPDec with format, number of digits either side of decimal place, initial value and all other attributes same as parameter PSPDec (copy constructor).
PSPDec(java.lang.String assignValue)
          Construct new PSPDec with default format and number of digits either side of decimal place and initial numeric value in parameter String.
 
Method Summary
 PSPDec add(PSPDec addValue)
          Add value of parameter PSPDec to this value (equivalent to the += operator) without rounding.
 PSPDec add(java.lang.String addValue)
          Add numeric value in parameter String to this value (equivalent to the += operator) without rounding.
 PSPDec addRound(PSPDec addValue)
          Add value of parameter PSPDec to this value (equivalent to the += operator) with rounding.
 PSPDec addRound(java.lang.String addValue)
          Add numeric value in parameter String to this value (equivalent to the += operator) with rounding.
 PSPDec assign(PSPDec assignValue)
          Assign value of parameter PSPDec to this value without rounding.
 PSPDec assign(java.lang.String assignValue)
          Assign numeric value in parameter String to this value without rounding.
 PSPDec assign(java.lang.String assignValue, char decimalPlace)
          Assign numeric value in parameter String to this value without rounding given the use of the parameter character for the decimal place in the String.
 PSPDec assignLeft(PSPDec assignValue)
          Assign value of parameter PSPDec to this value - digit-by-digit from left hand side (high-order) ignoring decimal places in both numbers.
 PSPDec assignLeftClear(PSPDec assignValue)
          Assign value of parameter PSPDec to this value - digit-by-digit from left hand side (high-order) ignoring decimal places in both numbers.
 PSPDec assignRight(PSPDec assignValue)
          Assign value of parameter PSPDec to this value - digit-by-digit from right hand side (low-order) ignoring decimal places in both numbers.
 PSPDec assignRightClear(PSPDec assignValue)
          Assign value of parameter PSPDec to this value - digit-by-digit from right hand side (low-order) ignoring decimal places in both numbers.
 PSPDec assignRound(PSPDec assignValue)
          Assign value of parameter PSPDec to this value with rounding.
 PSPDec assignRound(java.lang.String assignValue)
          Assign numeric value in parameter String to this value with rounding.
 PSPDec assignRound(java.lang.String value, char decimalPlace)
          Assign numeric value in parameter String to this value with rounding given the use of the parameter character for the decimal place in the String.
static int checkStringNumber(java.lang.String value, char decimalPlace)
          Check numeric value in parameter String given the use of the parameter character for the decimal place in the String.
static int checkStringNumber(java.lang.String value, char decimalPlace, java.lang.StringBuffer formattedValue)
          Check numeric value in parameter String given the use of the parameter character for the decimal place in the String.
static int checkStringNumber(java.lang.String value, PSPDecMask mask, java.lang.StringBuffer formattedValue)
          Check numeric value in parameter String given the use of the parameter mask for the fully formatted String.
 PSPDec clear()
          Clear value - set to zero.
 PSPDec divide(PSPDec divideValue)
          Divide this PSPDec by parameter PSPDec value (equivalent to the /= operator) without rounding.
 PSPDec divide(java.lang.String divideValue)
          Divide this PSPDec by numeric value in parameter String (equivalent to the /= operator) without rounding.
 PSPDec divideRemainder(PSPDec divideValue, PSPDec remainder)
          Divide this PSPDec by first parameter PSPDec value (equivalent to the /= operator) without rounding and assign remainder to second parameter PSPDec.
 PSPDec divideRemainder(java.lang.String divideValue, PSPDec remainder)
          Divide this PSPDec by numeric value in parameter String value (equivalent to the /= operator) without rounding and assign remainder to parameter PSPDec.
 PSPDec divideRound(PSPDec divideValue)
          Divide this PSPDec by parameter PSPDec value (equivalent to the /= operator) with rounding.
 PSPDec divideRound(java.lang.String divideValue)
          Divide this PSPDec by numeric value in parameter String (equivalent to the /= operator) with rounding.
 double doubleValue()
          Convert internal numeric value to a double via intermediate conversion to String s followed by the Double.valueOf(s).doubleValue() method.
 float floatValue()
          Convert internal numeric value to a float via call to doubleValue() which is then cast to a float.
 char getDecimalPlace()
          Gets decimal place for this PSPDec object.
 char getDecimalPlaceDefault()
          Gets default decimal place for PSPDec class (this is the default for any new PSPDec objects created).
 int getDigits()
          Retrieve current setting for total number of digits (before and after decimal place).
 int getDigitsAfterDP()
          Retrieve current setting for number of digits after decimal place.
 int getDigitsBeforeDP()
          Retrieve current setting for number of digits before decimal place.
 char getFormat()
          Retrieve current decimal format.
 char getFormatDefault()
          Retrieve decimal format default for new PSPDecs.
 byte getOverflow()
          Returns current setting for overflow following program operations.
 byte[] getPackedValue()
          Retrieve numeric value of this PSPDec in packed decimal format.
 int getUsedDigitsAfterDP()
          Determine number of digits after decimal place actually used for current numeric value.
 int getUsedDigitsBeforeDP()
          Determine number of digits before decimal place actually used for current numeric value.
 byte[] getValue()
          Retrieve numeric value of this PSPDec in format (zoned or packed decimal) currently specified for this PSPDec.
 int getValueLength()
          Retrieve length of byte array that would be returned by ( getValue() method.
 byte[] getZonedValue()
          Retrieve numeric value of this PSPDec in zoned decimal format.
 int intValue()
          Convert internal numeric value to an int via call to longValue() which is then cast to an int.
 boolean isEQ(PSPDec compareValue)
          Test if this PSPDec has numeric value same as parameter PSPDec.
 boolean isEQ(java.lang.String compareValue)
          Test if this PSPDec has value same as numeric value in parameter String.
 boolean isGE(PSPDec compareValue)
          Test if this PSPDec has numeric value greater than or equal to parameter PSPDec.
 boolean isGE(java.lang.String compareValue)
          Test if this PSPDec has value greater than or equal to numeric value in parameter String.
 boolean isGT(PSPDec compareValue)
          Test if this PSPDec has numeric value greater than parameter PSPDec.
 boolean isGT(java.lang.String compareValue)
          Test if this PSPDec has value greater than numeric value in parameter String.
 boolean isLE(PSPDec compareValue)
          Test if this PSPDec has numeric value less than or equal to parameter PSPDec.
 boolean isLE(java.lang.String compareValue)
          Test if this PSPDec has value less than or equal to numeric value in parameter String.
 boolean isLT(PSPDec compareValue)
          Test if this PSPDec has numeric value less than parameter PSPDec.
 boolean isLT(java.lang.String compareValue)
          Test if this PSPDec has value less than numeric value in parameter String.
 boolean isNE(PSPDec compareValue)
          Test if this PSPDec has numeric value not equal to parameter PSPDec.
 boolean isNE(java.lang.String compareValue)
          Test if this PSPDec has value not equal to numeric value in parameter String.
 boolean isNegative()
          Test if this PSPDec has negative numeric value.
 boolean isOddLength()
          Test if this PSPDec has total number of digits odd or even.
 boolean isPackedFormat()
          Test if cuurent format is packed decimal.
 boolean isPositive()
          Test if this PSPDec has positive numeric value.
 boolean isZero()
          Test if this PSPDec has zero numeric value.
 boolean isZonedFormat()
          Test if cuurent format is zoned decimal.
 long longValue()
          Convert internal numeric value to a long via intermediate conversion toString() followed by substring s selection of integer portion only which is then returned via Long.valueOf(s).longValue() method.
 PSPDec multiply(PSPDec multiplyValue)
          Multiply this value by value of parameter PSPDec (equivalent to the *= operator) without rounding.
 PSPDec multiply(java.lang.String multiplyValue)
          Multiply this value by numeric value in parameter String (equivalent to the *= operator) without rounding.
 PSPDec multiplyRound(PSPDec multiplyValue)
          Multiply this value by value of parameter PSPDec (equivalent to the *= operator) with rounding.
 PSPDec multiplyRound(java.lang.String multiplyValue)
          Multiply this value by numeric value in parameter String (equivalent to the *= operator) with rounding.
 char setDecimalPlace(char decimalPlace)
          Sets new decimal place for this PSPDec object (not for entire class) to specified character, which must not be whitespace (tab, newline, blank etc.) or a digit 0-9.
 char setDecimalPlaceDefault(char decimalPlaceDefault)
          Sets new default decimal place for PSPDec class to specified character, which must not be whitespace (tab, newline, blank etc.) or a digit 0-9.
 int setDigitsAfterDP(int digitsAfterDP)
          Reset number of digits after the decimal place for this PSPDec, without rounding if digits reduced.
 int setDigitsAfterDPRound(int digitsAfterDP)
          Reset number of digits after the decimal place for this PSPDec, with rounding if digits reduced.
 int setDigitsBeforeDP(int digitsBeforeDP)
          Reset number of digits before decimal place for this PSPDec, with treatment of overflow determined by getOverflow() if digits reduced.
 char setFormatDefault(char FormatDefault)
          Sets default class-level format for any new PSPDec.
 PSPDec setHighValue()
          Set numeric value of this PSPDec to highest possible value - every digit set to 9 and positive value assigned.
 PSPDec setLowValue()
          Set numeric value of this PSPDec to lowest possible value - every digit set to 9 and negative value assigned.
 void setOverflow(byte overflow)
          Set flag for this PSPDec (not for entire class) to control response to numeric overflow when new value set by program operations.
 void setOverflowDefault(byte overflowDefault)
          Set flag for PSPDec class (applied to new PSPDec's) to control response to numeric overflow when new value set by program operations.
 PSPDec setPackedValue(byte[] value)
          Sets internal numeric value from parameter byte array which must contain a valid packed decimal value with the required number of bytes determined by the getDigits() method.
 PSPDec setValue(byte[] value)
          Sets internal numeric value from parameter byte array which must contain a valid packed or zoned decimal value with the required number of bytes determined by the getDigits() method.
 PSPDec setZonedValue(byte[] value)
          Sets internal numeric value from parameter byte array which must contain a valid zoned decimal value with the required number of bytes determined by the getDigits() method.
 int signum()
          Returns the signum function of this PSPDec (-1, 0 or 1 as the value of this number is negative, zero or positive).
 PSPDec subtract(PSPDec subtractValue)
          Subtract value of parameter PSPDec from this value (equivalent to the -= operator) without rounding.
 PSPDec subtract(java.lang.String subtractValue)
          Subtract numeric value in parameter String from this value (equivalent to the -= operator) without rounding.
 PSPDec subtractRound(PSPDec subtractValue)
          Subtract value of parameter PSPDec from this value (equivalent to the -= operator) with rounding.
 PSPDec subtractRound(java.lang.String subtractValue)
          Subtract numeric value in parameter String from this value (equivalent to the -= operator) with rounding.
 java.lang.String toString()
          Returns the internal numeric value of this PSPDec as a String with the decimal place (if any) given by the getDecimalPlace() method.
 java.lang.String toString(char decimalPlace)
          Returns the internal numeric value of this PSPDec as a String with the decimal place (if any) given by the parameter character.
 java.lang.String toString(PSPDecMask mask)
          Returns the internal numeric value of this PSPDec as a fully formatted String with the decimal place and any other formatting given by the parameter mask.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_DIGITS_BEFORE

public static final int MAX_DIGITS_BEFORE
Maximum number (50) of digits before decimal place for PSPDec.

See Also:
Constant Field Values

MAX_DIGITS_AFTER

public static final int MAX_DIGITS_AFTER
Maximum number (50) of digits after decimal place for PSPDec.

See Also:
Constant Field Values

MAX_DIGITS

public static final int MAX_DIGITS
Maximum number (100) of digits in total (before and after decimal place) for PSPDec.

See Also:
Constant Field Values

OVERFLOW_BUMP_BEFOREDP

public static final byte OVERFLOW_BUMP_BEFOREDP
When overflow occurs, PSPDec automatically increments DigitsBeforeDP to accommodate the new value. This is the default for all new PSPDec's until you run the setOverflowDefault() method.

See Also:
Constant Field Values

OVERFLOW_EXCEPTION

public static final byte OVERFLOW_EXCEPTION
When overflow occurs, PSPDec throws a PSPException error for which getErrNum() returns PSPException.NumOverflow.

See Also:
Constant Field Values

OVERFLOW_IGNORE

public static final byte OVERFLOW_IGNORE
When overflow occurs, PSPDec silently ignores the new value.

See Also:
Constant Field Values

OVERFLOW_IGNORE_BEEP

public static final byte OVERFLOW_IGNORE_BEEP
When overflow occurs, PSPDec ignores the new value and beeps.

See Also:
Constant Field Values

OVERFLOW_TRUNCATE

public static final byte OVERFLOW_TRUNCATE
When overflow occurs, PSPDec silently truncates excess high-order digits.

See Also:
Constant Field Values

OVERFLOW_TRUNCATE_BEEP

public static final byte OVERFLOW_TRUNCATE_BEEP
When overflow occurs, PSPDec truncates excess high-order digits and beeps.

See Also:
Constant Field Values
Constructor Detail

PSPDec

public PSPDec(char format,
              int digitsBeforeDP,
              int digitsAfterDP)
       throws PSPException
Construct new PSPDec with specified format and number of digits either side of decimal place.

Parameters:
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.

PSPDec

public PSPDec(char format,
              int digitsBeforeDP,
              int digitsAfterDP,
              PSPDec assignValue)
       throws PSPException
Construct new PSPDec with specified format, number of digits either side of decimal place and initial value given by parameter PSPDec.

Parameters:
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.
assignValue - new value assigned to this object.

PSPDec

public PSPDec(char format,
              int digitsBeforeDP,
              int digitsAfterDP,
              java.lang.String assignValue)
       throws PSPException
Construct new PSPDec with specified format, number of digits either side of decimal place and initial numeric value in parameter String. Parameter String is assumed to have decimal place (if any) given by the getDecimalPlaceDefault() method.

Parameters:
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.
assignValue - new value assigned to this object.

PSPDec

public PSPDec(int digitsBeforeDP,
              int digitsAfterDP)
       throws PSPException
Construct new PSPDec with default format and number of digits either side of decimal place.

Parameters:
digitsBeforeDP - for number of digits before decimal place.
digitsAfterDP - for number of digits after decimal place.

PSPDec

public PSPDec(int digitsBeforeDP,
              int digitsAfterDP,
              PSPDec assignValue)
       throws PSPException
Construct new PSPDec with default format, number of digits either side of decimal place and initial value given by parameter PSPDec.

Parameters:
digitsBeforeDP - for number of digits before decimal place.
digitsAfterDP - for number of digits after decimal place.
assignValue - new value assigned to this object.

PSPDec

public PSPDec(int digitsBeforeDP,
              int digitsAfterDP,
              java.lang.String assignValue)
       throws PSPException
Construct new PSPDec with default format, number of digits either side of decimal place and initial numeric value in parameter String. Parameter String is assumed to have decimal place (if any) given by the getDecimalPlaceDefault() method.

Parameters:
digitsBeforeDP - for number of digits before decimal place.
digitsAfterDP - for number of digits after decimal place.
assignValue - new value assigned to this object.

PSPDec

public PSPDec(PSPDec copyDec)
       throws PSPException
Construct new PSPDec with format, number of digits either side of decimal place, initial value and all other attributes same as parameter PSPDec (copy constructor).

Parameters:
copyDec - the PSPDec to be copied.

PSPDec

public PSPDec(java.lang.String assignValue)
       throws PSPException
Construct new PSPDec with default format and number of digits either side of decimal place and initial numeric value in parameter String. The new PSPDec initially gets the decimal place character given by the getDecimalPlaceDefault(). method, which is the decimal place (if any) which it expects to find in the parameter String. If the string has a different decimal place, construct the PSPDec another way, then execute setDecimalPlace(char). and assign(String).

Parameters:
assignValue - string holding numeric value from which this PSPDec to be constructed.
Method Detail

add

public PSPDec add(PSPDec addValue)
           throws PSPException
Add value of parameter PSPDec to this value (equivalent to the += operator) without rounding.

Parameters:
addValue - value to be added into this PSPDec.
Returns:
this PSPDec after the addition.
PSPException

add

public PSPDec add(java.lang.String addValue)
           throws PSPException
Add numeric value in parameter String to this value (equivalent to the += operator) without rounding.

Parameters:
addValue - value to be added into this PSPDec.
Returns:
this PSPDec after the addition.
PSPException

addRound

public PSPDec addRound(PSPDec addValue)
                throws PSPException
Add value of parameter PSPDec to this value (equivalent to the += operator) with rounding.

Parameters:
addValue - value to be added into this PSPDec.
Returns:
this PSPDec after the addition.
PSPException

addRound

public PSPDec addRound(java.lang.String addValue)
                throws PSPException
Add numeric value in parameter String to this value (equivalent to the += operator) with rounding.

Parameters:
addValue - value to be added into this PSPDec.
Returns:
this PSPDec after the addition.
PSPException

assign

public PSPDec assign(PSPDec assignValue)
              throws PSPException
Assign value of parameter PSPDec to this value without rounding.

Parameters:
assignValue - value to be assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assign

public PSPDec assign(java.lang.String assignValue)
              throws PSPException
Assign numeric value in parameter String to this value without rounding. Parameter String is assumed to have the decimal place (if any) given by the getDecimalPlace() method.

Parameters:
assignValue - value to be assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assign

public PSPDec assign(java.lang.String assignValue,
                     char decimalPlace)
              throws PSPException
Assign numeric value in parameter String to this value without rounding given the use of the parameter character for the decimal place in the String.

Parameters:
assignValue - value to be assigned to this PSPDec.
decimalPlace - the character used for the decimal place in the String.
Returns:
this PSPDec after the assignment.
PSPException

assignLeft

public PSPDec assignLeft(PSPDec assignValue)
                  throws PSPException
Assign value of parameter PSPDec to this value - digit-by-digit from left hand side (high-order) ignoring decimal places in both numbers. Any excess low-order digits are ignored. The sign of the value is determined by the sign of the parameter PSPDec unless it has less digits in total than this - in which case the sign of this is preserved.

Parameters:
assignValue - value to be left-assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assignLeftClear

public PSPDec assignLeftClear(PSPDec assignValue)
                       throws PSPException
Assign value of parameter PSPDec to this value - digit-by-digit from left hand side (high-order) ignoring decimal places in both numbers. The value of this is set to zero before the assignment. The sign of the value is determined by the sign of the parameter PSPDec unless it has less digits in total than this - in which case the sign of this is preserved.

Parameters:
assignValue - value to be left-assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assignRight

public PSPDec assignRight(PSPDec assignValue)
                   throws PSPException
Assign value of parameter PSPDec to this value - digit-by-digit from right hand side (low-order) ignoring decimal places in both numbers. Any excess high-order digits are ignored. The sign of the value is determined by the sign of the parameter PSPDec.

Parameters:
assignValue - value to be right-assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assignRightClear

public PSPDec assignRightClear(PSPDec assignValue)
                        throws PSPException
Assign value of parameter PSPDec to this value - digit-by-digit from right hand side (low-order) ignoring decimal places in both numbers. The value of this is set to zero before the assignment. The sign of the value is determined by the sign of the parameter PSPDec.

Parameters:
assignValue - value to be right-assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assignRound

public PSPDec assignRound(PSPDec assignValue)
                   throws PSPException
Assign value of parameter PSPDec to this value with rounding.

Parameters:
assignValue - value to be assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assignRound

public PSPDec assignRound(java.lang.String assignValue)
                   throws PSPException
Assign numeric value in parameter String to this value with rounding. Parameter String is assumed to have the decimal place (if any) given by the getDecimalPlace() method.

Parameters:
assignValue - value to be assigned to this PSPDec.
Returns:
this PSPDec after the assignment.
PSPException

assignRound

public PSPDec assignRound(java.lang.String value,
                          char decimalPlace)
                   throws PSPException
Assign numeric value in parameter String to this value with rounding given the use of the parameter character for the decimal place in the String.

Parameters:
decimalPlace - the character used for the decimal place in the String.
Returns:
this PSPDec after the assignment.
PSPException

checkStringNumber

public static int checkStringNumber(java.lang.String value,
                                    char decimalPlace)
                             throws PSPException
Check numeric value in parameter String given the use of the parameter character for the decimal place in the String.

Parameters:
value - String containing numeric value.
decimalPlace - the character used for the decimal place in the String.
Returns:
position of error in numeric string (-1 if no error).
PSPException

checkStringNumber

public static int checkStringNumber(java.lang.String value,
                                    char decimalPlace,
                                    java.lang.StringBuffer formattedValue)
                             throws PSPException
Check numeric value in parameter String given the use of the parameter character for the decimal place in the String. Return reformatted string in parameter buffer.

Parameters:
value - String containing numeric value.
decimalPlace - the character used for the decimal place in the String.
formattedValue - the String value reformatted (should only be used if return value indicates no error).
Returns:
position of error in numeric string (-1 if no error).
PSPException

checkStringNumber

public static int checkStringNumber(java.lang.String value,
                                    PSPDecMask mask,
                                    java.lang.StringBuffer formattedValue)
                             throws PSPException
Check numeric value in parameter String given the use of the parameter mask for the fully formatted String. Return deformatted string (decimal place and sign only) in parameter buffer.

Parameters:
value - String containing numeric value.
mask - the mask used to fully format the String numeric value.
formattedValue - the String value deformatted (should only be used if return value indicates no error).
Returns:
position of error in numeric string (-1 if no error).
PSPException

clear

public PSPDec clear()
             throws PSPException
Clear value - set to zero.

Returns:
this PSPDec after the value cleared.
PSPException

divide

public PSPDec divide(PSPDec divideValue)
              throws PSPException
Divide this PSPDec by parameter PSPDec value (equivalent to the /= operator) without rounding.

Parameters:
divideValue - value to be divided into this PSPDec.
Returns:
this PSPDec after the division.
PSPException

divide

public PSPDec divide(java.lang.String divideValue)
              throws PSPException
Divide this PSPDec by numeric value in parameter String (equivalent to the /= operator) without rounding.

Parameters:
divideValue - value to be divided into this PSPDec.
Returns:
this PSPDec after the division.
PSPException

divideRemainder

public PSPDec divideRemainder(PSPDec divideValue,
                              PSPDec remainder)
                       throws PSPException
Divide this PSPDec by first parameter PSPDec value (equivalent to the /= operator) without rounding and assign remainder to second parameter PSPDec.

Parameters:
divideValue - value to be divided into this PSPDec.
remainder - PSPDec to hold remainder after division.
Returns:
this PSPDec after the division.
PSPException

divideRemainder

public PSPDec divideRemainder(java.lang.String divideValue,
                              PSPDec remainder)
                       throws PSPException
Divide this PSPDec by numeric value in parameter String value (equivalent to the /= operator) without rounding and assign remainder to parameter PSPDec.

Parameters:
divideValue - value to be divided into this PSPDec.
remainder - PSPDec to hold remainder after division.
Returns:
this PSPDec after the division.
PSPException

divideRound

public PSPDec divideRound(PSPDec divideValue)
                   throws PSPException
Divide this PSPDec by parameter PSPDec value (equivalent to the /= operator) with rounding.

Parameters:
divideValue - value to be divided into this PSPDec.
Returns:
this PSPDec after the division.
PSPException

divideRound

public PSPDec divideRound(java.lang.String divideValue)
                   throws PSPException
Divide this PSPDec by numeric value in parameter String (equivalent to the /= operator) with rounding.

Parameters:
divideValue - value to be divided into this PSPDec.
Returns:
this PSPDec after the division.
PSPException

getDecimalPlace

public char getDecimalPlace()
Gets decimal place for this PSPDec object.

Returns:
character currently specified as decimal place for this object.

getDecimalPlaceDefault

public char getDecimalPlaceDefault()
Gets default decimal place for PSPDec class (this is the default for any new PSPDec objects created).

Returns:
character currently specified as default for decimal place.

getDigitsAfterDP

public int getDigitsAfterDP()
Retrieve current setting for number of digits after decimal place.

Returns:
number of digits after decimal place.

getUsedDigitsAfterDP

public int getUsedDigitsAfterDP()
Determine number of digits after decimal place actually used for current numeric value. For example, if the current value is 005000.0500 then this function returns the value 2. The value returned will never exceed that returned by getDigitsAfterDP().

Returns:
number of digits after decimal place actually used.

getDigitsBeforeDP

public int getDigitsBeforeDP()
Retrieve current setting for number of digits before decimal place.

Returns:
number of digits before decimal place.

getUsedDigitsBeforeDP

public int getUsedDigitsBeforeDP()
Determine number of digits before decimal place actually used for current numeric value. For example, if the current value is 005000.0500 then this function returns the value 4. The value returned will never exceed that returned by getDigitsBeforeDP().

Returns:
number of digits before decimal place actually used.

getDigits

public int getDigits()
Retrieve current setting for total number of digits (before and after decimal place).

Returns:
number of digits total.

getFormat

public char getFormat()
Retrieve current decimal format.

Returns:
current format: 'P' for packed decimal, 'Z' for zoned decimal.

isPackedFormat

public boolean isPackedFormat()
Test if cuurent format is packed decimal.


isZonedFormat

public boolean isZonedFormat()
Test if cuurent format is zoned decimal.


getFormatDefault

public char getFormatDefault()
Retrieve decimal format default for new PSPDecs.

Returns:
current default format: 'P' for packed decimal, 'Z' for zoned decimal.

getPackedValue

public byte[] getPackedValue()
                      throws PSPException
Retrieve numeric value of this PSPDec in packed decimal format.

Returns:
byte array holding packed decimal value.
PSPException

getOverflow

public byte getOverflow()
Returns current setting for overflow following program operations.

Returns:
Value for Overflow flag (integer value corresponding to OVERFLOW_xxx value set by preceding setOverflow() operation).

getValue

public byte[] getValue()
                throws PSPException
Retrieve numeric value of this PSPDec in format (zoned or packed decimal) currently specified for this PSPDec.

Returns:
byte array holding packed or zoned decimal value.
PSPException

getValueLength

public int getValueLength()
Retrieve length of byte array that would be returned by ( getValue() method.

Returns:
length of byte array that would be returned by getValue() method.

getZonedValue

public byte[] getZonedValue()
                     throws PSPException
Retrieve numeric value of this PSPDec in zoned decimal format.

Returns:
byte array holding zoned decimal value.
PSPException

isEQ

public boolean isEQ(PSPDec compareValue)
             throws PSPException
Test if this PSPDec has numeric value same as parameter PSPDec.

Parameters:
compareValue - PSPDec with value to be compared.
Returns:
true if this PSPDec has value equal to parameter value, otherwise false.
PSPException

isEQ

public boolean isEQ(java.lang.String compareValue)
             throws PSPException
Test if this PSPDec has value same as numeric value in parameter String.

Parameters:
compareValue - String holding numeric value to be compared.
Returns:
true if this PSPDec has value equal to parameter value, otherwise false.
PSPException

isGE

public boolean isGE(PSPDec compareValue)
             throws PSPException
Test if this PSPDec has numeric value greater than or equal to parameter PSPDec.

Parameters:
compareValue - PSPDec with value to be compared.
Returns:
true if this PSPDec has value >= parameter value, otherwise false.
PSPException

isGE

public boolean isGE(java.lang.String compareValue)
             throws PSPException
Test if this PSPDec has value greater than or equal to numeric value in parameter String.

Parameters:
compareValue - String holding numeric value to be compared.
Returns:
true if this PSPDec has value >= parameter value, otherwise false.
PSPException

isGT

public boolean isGT(PSPDec compareValue)
             throws PSPException
Test if this PSPDec has numeric value greater than parameter PSPDec.

Parameters:
compareValue - PSPDec value to be compared.
Returns:
true if this PSPDec has value > parameter value, otherwise false.
PSPException

isGT

public boolean isGT(java.lang.String compareValue)
             throws PSPException
Test if this PSPDec has value greater than numeric value in parameter String.

Parameters:
compareValue - String holding numeric value to be compared.
Returns:
true if this PSPDec has value > parameter value, otherwise false.
PSPException

isLE

public boolean isLE(PSPDec compareValue)
             throws PSPException
Test if this PSPDec has numeric value less than or equal to parameter PSPDec.

Parameters:
compareValue - PSPDec with value to be compared.
Returns:
true if this PSPDec has value <= parameter value, otherwise false.
PSPException

isLE

public boolean isLE(java.lang.String compareValue)
             throws PSPException
Test if this PSPDec has value less than or equal to numeric value in parameter String.

Parameters:
compareValue - String holding numeric value to be compared.
Returns:
true if this PSPDec has value <= parameter value, otherwise false.
PSPException

isLT

public boolean isLT(PSPDec compareValue)
             throws PSPException
Test if this PSPDec has numeric value less than parameter PSPDec.

Parameters:
compareValue - PSPDec with value to be compared.
Returns:
true if this PSPDec has value < parameter value, otherwise false.
PSPException

isLT

public boolean isLT(java.lang.String compareValue)
             throws PSPException
Test if this PSPDec has value less than numeric value in parameter String.

Parameters:
compareValue - String holding numeric value to be compared.
Returns:
true if this PSPDec has value < parameter value, otherwise false.
PSPException

isNE

public boolean isNE(PSPDec compareValue)
             throws PSPException
Test if this PSPDec has numeric value not equal to parameter PSPDec.

Parameters:
compareValue - PSPDec with value to be compared.
Returns:
true if this PSPDec has value != parameter value, otherwise false.
PSPException

isNE

public boolean isNE(java.lang.String compareValue)
             throws PSPException
Test if this PSPDec has value not equal to numeric value in parameter String.

Parameters:
compareValue - String holding numeric value to be compared.
Returns:
true if this PSPDec has value != parameter value, otherwise false.
PSPException

isNegative

public boolean isNegative()
                   throws PSPException
Test if this PSPDec has negative numeric value.

Returns:
true if this PSPDec has negative value, otherwise false.
PSPException

isPositive

public boolean isPositive()
                   throws PSPException
Test if this PSPDec has positive numeric value.

Returns:
true if this PSPDec has positive value, otherwise false.
PSPException

isZero

public boolean isZero()
               throws PSPException
Test if this PSPDec has zero numeric value.

Returns:
true if this PSPDec has zero value, otherwise false.
PSPException

isOddLength

public boolean isOddLength()
Test if this PSPDec has total number of digits odd or even.

Returns:
true if this PSPDec has odd number of digits in total, otherwise false.

multiply

public PSPDec multiply(PSPDec multiplyValue)
                throws PSPException
Multiply this value by value of parameter PSPDec (equivalent to the *= operator) without rounding.

Parameters:
multiplyValue - value to multiply this PSPDec by.
Returns:
this PSPDec after the multiplication.
PSPException

multiply

public PSPDec multiply(java.lang.String multiplyValue)
                throws PSPException
Multiply this value by numeric value in parameter String (equivalent to the *= operator) without rounding.

Parameters:
multiplyValue - value to multiply this PSPDec by.
Returns:
this PSPDec after the multiplication.
PSPException

multiplyRound

public PSPDec multiplyRound(PSPDec multiplyValue)
                     throws PSPException
Multiply this value by value of parameter PSPDec (equivalent to the *= operator) with rounding.

Parameters:
multiplyValue - value to multiply this PSPDec by.
Returns:
this PSPDec after the multiplication.
PSPException

multiplyRound

public PSPDec multiplyRound(java.lang.String multiplyValue)
                     throws PSPException
Multiply this value by numeric value in parameter String (equivalent to the *= operator) with rounding.

Parameters:
multiplyValue - value to multiply this PSPDec by.
Returns:
this PSPDec after the multiplication.
PSPException

setDecimalPlace

public char setDecimalPlace(char decimalPlace)
Sets new decimal place for this PSPDec object (not for entire class) to specified character, which must not be whitespace (tab, newline, blank etc.) or a digit 0-9. Until this method is called, the decimal place is the character returned by the getDecimalPlaceDefault() method.

Parameters:
decimalPlace - new character for decimal place.
Returns:
new character for decimal place for this PSPDec.

setDecimalPlaceDefault

public char setDecimalPlaceDefault(char decimalPlaceDefault)
Sets new default decimal place for PSPDec class to specified character, which must not be whitespace (tab, newline, blank etc.) or a digit 0-9. This is the decimal place for any new PSPDec objects. Until this method is called, the default decimal place for the PSPDec class is the full-stop character (.).

Parameters:
decimalPlaceDefault - character specified as default for decimal place.
Returns:
new character specified as default for decimal place.

setDigitsAfterDP

public int setDigitsAfterDP(int digitsAfterDP)
                     throws PSPException
Reset number of digits after the decimal place for this PSPDec, without rounding if digits reduced.

Parameters:
digitsAfterDP - the new number of digits after the decimal place.
Returns:
the accepted number of digits after the decimal place.
PSPException

setDigitsAfterDPRound

public int setDigitsAfterDPRound(int digitsAfterDP)
                          throws PSPException
Reset number of digits after the decimal place for this PSPDec, with rounding if digits reduced.

Parameters:
digitsAfterDP - the new number of digits after the decimal place.
Returns:
the accepted number of digits after the decimal place.
PSPException

setDigitsBeforeDP

public int setDigitsBeforeDP(int digitsBeforeDP)
                      throws PSPException
Reset number of digits before decimal place for this PSPDec, with treatment of overflow determined by getOverflow() if digits reduced.

Parameters:
digitsBeforeDP - the new number of digits before the decimal place.
Returns:
the accepted number of digits before the decimal place.
PSPException

setFormatDefault

public char setFormatDefault(char FormatDefault)
Sets default class-level format for any new PSPDec. Until this method is called, the default format is 'P' for packed decimal.

Parameters:
FormatDefault - new format default: 'P' for packed decimal, 'Z' for zoned decimal.
Returns:
the accepted format default.

setHighValue

public PSPDec setHighValue()
                    throws PSPException
Set numeric value of this PSPDec to highest possible value - every digit set to 9 and positive value assigned.

Returns:
this PSPDec after value reset to highest possible.
PSPException

setLowValue

public PSPDec setLowValue()
                   throws PSPException
Set numeric value of this PSPDec to lowest possible value - every digit set to 9 and negative value assigned.

Returns:
this PSPDec after value reset to lowest possible.
PSPException

setOverflow

public void setOverflow(byte overflow)
Set flag for this PSPDec (not for entire class) to control response to numeric overflow when new value set by program operations. New flag setting must be one of OVERFLOW_TRUNCATE_BEEP, OVERFLOW_TRUNCATE, OVERFLOW_IGNORE_BEEP, OVERFLOW_IGNORE, OVERFLOW_BUMP_BEFOREDP or OVERFLOW_EXCEPTION.

Parameters:
overflow - Flag controlling overflow response.

setOverflowDefault

public void setOverflowDefault(byte overflowDefault)
Set flag for PSPDec class (applied to new PSPDec's) to control response to numeric overflow when new value set by program operations. New flag setting must be one of OVERFLOW_TRUNCATE_BEEP, OVERFLOW_TRUNCATE, OVERFLOW_IGNORE_BEEP, OVERFLOW_IGNORE, OVERFLOW_BUMP_BEFOREDP or OVERFLOW_EXCEPTION. Until this method is called, the default is OVERFLOW_BUMP_BEFOREDP.

Parameters:
overflowDefault - Flag controlling overflow response.

setPackedValue

public PSPDec setPackedValue(byte[] value)
                      throws PSPException
Sets internal numeric value from parameter byte array which must contain a valid packed decimal value with the required number of bytes determined by the getDigits() method.

Parameters:
value - byte array containing new packed decimal value.
Returns:
this PSPDec after new value assigned.
PSPException

setValue

public PSPDec setValue(byte[] value)
                throws PSPException
Sets internal numeric value from parameter byte array which must contain a valid packed or zoned decimal value with the required number of bytes determined by the getDigits() method. The format of the parameter value (zoned or packed) must match that determined by the getFormat() method.

Parameters:
value - byte array containing new packed/zoned decimal value.
Returns:
this PSPDec after new value assigned.
PSPException

setZonedValue

public PSPDec setZonedValue(byte[] value)
                     throws PSPException
Sets internal numeric value from parameter byte array which must contain a valid zoned decimal value with the required number of bytes determined by the getDigits() method.

Parameters:
value - byte array containing new zoned decimal value.
Returns:
this PSPDec after new value assigned.
PSPException

signum

public int signum()
Returns the signum function of this PSPDec (-1, 0 or 1 as the value of this number is negative, zero or positive).

Returns:
-1, 0 or 1 for the value of this number is negative, zero or positive

subtract

public PSPDec subtract(PSPDec subtractValue)
                throws PSPException
Subtract value of parameter PSPDec from this value (equivalent to the -= operator) without rounding.

Parameters:
subtractValue - value to be subtracted from this PSPDec.
Returns:
this PSPDec after the subtraction.
PSPException

subtract

public PSPDec subtract(java.lang.String subtractValue)
                throws PSPException
Subtract numeric value in parameter String from this value (equivalent to the -= operator) without rounding.

Parameters:
subtractValue - value to be subtracted from this PSPDec.
Returns:
this PSPDec after the subtraction.
PSPException

subtractRound

public PSPDec subtractRound(PSPDec subtractValue)
                     throws PSPException
Subtract value of parameter PSPDec from this value (equivalent to the -= operator) with rounding.

Parameters:
subtractValue - value to be subtracted from this PSPDec.
Returns:
this PSPDec after the subtraction.
PSPException

subtractRound

public PSPDec subtractRound(java.lang.String subtractValue)
                     throws PSPException
Subtract numeric value in parameter String from this value (equivalent to the -= operator) with rounding.

Parameters:
subtractValue - value to be subtracted from this PSPDec.
Returns:
this PSPDec after the subtraction.
PSPException

toString

public java.lang.String toString()
                          throws PSPException
Returns the internal numeric value of this PSPDec as a String with the decimal place (if any) given by the getDecimalPlace() method.

Overrides:
toString in class java.lang.Object
Returns:
numeric value of this PSPDec as a String.
PSPException

toString

public java.lang.String toString(char decimalPlace)
                          throws PSPException
Returns the internal numeric value of this PSPDec as a String with the decimal place (if any) given by the parameter character.

Parameters:
decimalPlace - the character to be used as the decimal place in the returned String.
Returns:
numeric value of this PSPDec as a String.
PSPException

toString

public java.lang.String toString(PSPDecMask mask)
                          throws PSPException
Returns the internal numeric value of this PSPDec as a fully formatted String with the decimal place and any other formatting given by the parameter mask.

Parameters:
mask - the mask used to format the String.
Returns:
numeric value of this PSPDec as a fully formatted String.
PSPException

intValue

public int intValue()
             throws PSPException
Convert internal numeric value to an int via call to longValue() which is then cast to an int.

Returns:
internal value as an int.
PSPException

longValue

public long longValue()
               throws PSPException,
                      java.lang.NumberFormatException
Convert internal numeric value to a long via intermediate conversion toString() followed by substring s selection of integer portion only which is then returned via Long.valueOf(s).longValue() method.

Returns:
internal value as a long.
Throws:
PSPException