IMC Epclient 5.0.3

at.spardat.enterprise.fmt
Class ABcdFmtDefault

java.lang.Object
  extended byat.spardat.enterprise.fmt.IFmt
      extended byat.spardat.enterprise.fmt.ABcdFmt
          extended byat.spardat.enterprise.fmt.ABcdFmtDefault
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ABcdFmtPattern, ABcdFmtRange

public class ABcdFmtDefault
extends ABcdFmt

This implementation allows to parse and format internationalized numbers. It's a performance optimized implementation to support formatting and parsing of values coming from ABcds.

The internal encoding is the canonical encoding defined in class ABcd, i.e., decimal separator is the point, for example 100000.23.


Field Summary
static int NK_ERROR
           
static int NK_TRUNC
           
 
Fields inherited from class at.spardat.enterprise.fmt.ABcdFmt
NO_NEG, NO_THOUS_SEPS, ROUND_FRACTION, SUPPRESS_ZERO, THOUS_SEPS
 
Fields inherited from class at.spardat.enterprise.fmt.IFmt
DEFAULT, LAST_STYLE, MANDATORY, style_
 
Constructor Summary
ABcdFmtDefault(int maxBeforeC, int maxAfterC, int style, java.util.Locale l)
          Constructs an ABcdFmt.
 
Method Summary
 java.lang.String format(java.lang.String internal)
          Transforms an internal encoding to an external.
static java.lang.String format(java.lang.String canonic, char tSep, char decSep, int numNachKomma)
          Takes a canonic string as input and returns a formatted string.
 int getMaxAfterC()
          Returns maximum number of digits after decimal separator or -1, if number of digits after decimal separator is unrestricted.
 int getMaxBeforeC()
          Return maximum number of digits before decimal separator or -1, if number of digits before decimal separator is unrestricted.
 boolean isLegalExternalChar(char aChar)
          Examines whether a given character may be part of an external representation.
 boolean isLegalInternal(java.lang.String v)
          Determines if the given string is a legal internal representation.
 boolean isOneWay()
          An IFmt is one way, if the external encoding may be generated out of the internal, but not vice versa.
 int maxLenOfExternal()
          Returns the maximum length an external string representation may have.
 java.lang.String parse(java.lang.String external)
          Tries to transform an external encoding to an internal.
static void parse(java.lang.String in, java.lang.StringBuffer result, int maxVK, int maxNK, char tSep, char decSep, int excessNKMode)
          This method parses an external representation of a ABcd and converts it to the canonic format.
 void set(int maxBeforeC, int maxAfterC, int style, java.util.Locale l)
          Allows to set all parameters that determine the formatting process.
 void setMaxAfterC(int maxAfterC_)
          Sets maximum number of digits after decimal separator.
 void setMaxBeforeC(int maxBeforeC_)
          Sets maximum number of digits before the decimal separator.
 void setStyle(int style_)
          Sets the style.
 
Methods inherited from class at.spardat.enterprise.fmt.ABcdFmt
getInstance, getInstance, getInstance, mayBeAppliedTo
 
Methods inherited from class at.spardat.enterprise.fmt.IFmt
checkMandatory, clone, getStyle, isMandatory, setMandatory
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NK_TRUNC

public static final int NK_TRUNC
See Also:
Constant Field Values

NK_ERROR

public static final int NK_ERROR
See Also:
Constant Field Values
Constructor Detail

ABcdFmtDefault

public ABcdFmtDefault(int maxBeforeC,
                      int maxAfterC,
                      int style,
                      java.util.Locale l)
Constructs an ABcdFmt.

See Also:
set(int, int, int, java.util.Locale)
Method Detail

set

public void set(int maxBeforeC,
                int maxAfterC,
                int style,
                java.util.Locale l)
Allows to set all parameters that determine the formatting process.

Parameters:
maxBeforeC - max number of digits before the comma or -1 if unrestricted. Must not be zero.
maxAfterC - max number of digits after the comma or -1 if unrestricted
style - may be DEFAULT, MANDATORY, NO_THOUS_SEPS, THOUS_SEPS, NO_NEG or ROUND_FRACTION. Either NO_THOUS_SEPS or THOUS_SEPS may be specified.
l - the Locale. Must not be null.
Throws:
java.lang.IllegalArgumentException - if maxBeforeC is zero

setMaxAfterC

public void setMaxAfterC(int maxAfterC_)
Sets maximum number of digits after decimal separator.


setMaxBeforeC

public void setMaxBeforeC(int maxBeforeC_)
Sets maximum number of digits before the decimal separator.


getMaxAfterC

public int getMaxAfterC()
Returns maximum number of digits after decimal separator or -1, if number of digits after decimal separator is unrestricted.


getMaxBeforeC

public int getMaxBeforeC()
Return maximum number of digits before decimal separator or -1, if number of digits before decimal separator is unrestricted.


setStyle

public void setStyle(int style_)
Sets the style.


format

public java.lang.String format(java.lang.String internal)
Description copied from class: IFmt
Transforms an internal encoding to an external.

Specified by:
format in class IFmt
Parameters:
internal - the provided internal encoding. This String must satisfy the condition isLegalInternal(), otherwise the behaviour of this method is undefined.
Returns:
the external representation. May be the empty string, but is never null.
See Also:
IFmt.format(String)

isLegalExternalChar

public boolean isLegalExternalChar(char aChar)
Description copied from class: IFmt
Examines whether a given character may be part of an external representation.

Specified by:
isLegalExternalChar in class IFmt
Parameters:
aChar - the character to check
Returns:
boolean if the character may be part of an external rep.
See Also:
IFmt.isLegalExternalChar(char)

isLegalInternal

public boolean isLegalInternal(java.lang.String v)
Description copied from class: IFmt
Determines if the given string is a legal internal representation.

Specified by:
isLegalInternal in class IFmt
Parameters:
v - the internal encoding.
Returns:
whether the provided string follows a legal internal encoding.
See Also:
IFmt.isLegalInternal(String)

isOneWay

public boolean isOneWay()
Description copied from class: IFmt
An IFmt is one way, if the external encoding may be generated out of the internal, but not vice versa.

Specified by:
isOneWay in class IFmt
Returns:
true, if format may be called, but parse not.
See Also:
IFmt.isOneWay()

maxLenOfExternal

public int maxLenOfExternal()
Description copied from class: IFmt
Returns the maximum length an external string representation may have.

Specified by:
maxLenOfExternal in class IFmt
Returns:
the maximum length or -1 if there is no known maximum.
See Also:
IFmt.maxLenOfExternal()

parse

public java.lang.String parse(java.lang.String external)
                       throws AParseException
Description copied from class: IFmt
Tries to transform an external encoding to an internal. Must not be called if isOneWay() yields true.

Specified by:
parse in class IFmt
Parameters:
external - the external encoding
Returns:
the internal encoding. May be the empty String, but never is null.
Throws:
AParseException - if the external encoding cannot be successfully parsed.
See Also:
IFmt.parse(String)

parse

public static void parse(java.lang.String in,
                         java.lang.StringBuffer result,
                         int maxVK,
                         int maxNK,
                         char tSep,
                         char decSep,
                         int excessNKMode)
This method parses an external representation of a ABcd and converts it to the canonic format.

Parameters:
in - the input string. May contain leading and trailing zeros.
result - must be an empty StringBuffer which is going to hold the result. The computed string in the canonic format, which may be safely assigned to an ABcd, if the precision attributes maxVK and maxNK are drawn from it. An empty string is returned if in is empty or just consists of blanks.
maxVK - maximum number of digits in front of the decimal point. Specify -1, if no restriction should be imposed.
maxNK - maximum number of digits after the decimal point or -1, if no restriction should be applied.
tSep - A thousands separation character, which is generally ignored in the part before the comma. May be 0, then in must not contain thousand separation characters.
decSep - The decimal separation character expected in the input.
excessNKMode - either NK_TRUNC or NK_ERROR. Defines how to react if more than maxNK places after the decimal point are present (after removing trailing zeros).
Throws:
FmtParseException - if in cannot be converted to the internal format.

format

public static java.lang.String format(java.lang.String canonic,
                                      char tSep,
                                      char decSep,
                                      int numNachKomma)
Takes a canonic string as input and returns a formatted string.

Parameters:
canonic - canonic format string of a ABcd
tSep - if not equal to zero, this character is inserted at thousand separation position
decSep - this character is used as decimal point character in the result
numNachKomma - if greater than or equal zero, the result will have numNachKomma places after the decimal point. If it is -1, the result consists of as many digits after the comma as necessary.
Returns:
the formatted string. It does not have leading zeros.

IMC Epclient 5.0.3