borland Packages Class Hierarchy dx.text Package
java.lang.Object +----com.borland.dx.text.ItemFormatter +----com.borland.dx.text.VariantFormatter +----com.borland.dx.text.VariantFormatStr
Constructors Properties Methods
The VariantFormatStr
class extends the VariantFormatter
class through the use of
String
patterns to control formatting and parsing. It can handle all Variant
types. Other formatter classes exist that are built to handle a specific Variant
type.
There are five different kinds of pattern strings which can be used.
Each is distinct, and the fields from one cannot be used with another.
The type used will be inferred from the Variant
.type passed into the
constructor. The types are:
See edit/display masks for information about using the various patterns.
public VariantFormatStr(String pattern, int variantType)Constructs a
VariantFormatStr
object that specifies the pattern used to format values and the type of data the object formats and parses.
pattern
format()
method. If this value is null (or empty), the best default pattern is automatically selected based on the locale.
variantType
Variant
data type that is used by the format()
and parse()
methods.
public VariantFormatStr(String pattern, int variantType, Locale locale)Constructs a
VariantFormatStr
object that specifies the pattern used to format values, the type of data the object formats and parses, and the locale.
pattern
format()
method. If this value is null (or empty), the best default pattern is automatically selected based on the locale.
variantType
Variant
data type that is used by the format()
and parse()
methods.
locale
locale
is null, the current default locale is used.
public VariantFormatStr(String pattern, int variantType, Locale locale, int scale, int precision, boolean isCurrency)Constructs a
VariantFormatStr
object that specifies the pattern used to format values, the type of data the object formats and parses, the locale, and other formatting information.
pattern
format()
method. If this value is null (or empty), the best default pattern is automatically selected based on the locale.
variantType
Variant
data type that is used by the format()
and parse()
methods.
locale
locale
is null, the current default locale is used.
scale
BigDecimal
data types. Any value other than -1 selects the number of decimal digits used in formatting and parsing BigDecimal
values. Note that pattern
must still express the number of digits to be displayed.
precision
precision
is not used.
isCurrency
isCurrency
is true, the data is a currency value.
public Format getFormatObj()Returns the JDK
Format
subclass associated with this formatter. A returned value of null is possible.
public Locale getLocale()Returns the
Locale
object being used by this formatting class. The returned value will never be null.
public String getPattern()Returns the pattern used by this
VariantFormatStr
object for formatting and parsing. See edit/display patterns.
public int getScale()Returns the current scale factor, which is relevant only for
BigDecimal
data.
public int getVariantType()Returns the
Variant
type for this VariantFormatStr
object.
public static final String buildTrueFormatMask(String editMask)Returns a pattern string, removing any borland.com-specific extensions.
edit
public String format(Variant value)Returns a formatted string from the value specified with the
value
parameter. format()
uses the current pattern to format the value. format()
does not support all data types, but an attempt is made to cast the Variant
data into a type required by the formatting logic.
The returned formatted string could be empty if the input Variant
was null or unassigned. A null is returned if the formatting fails.
value
value
isn't a Variant
, the method throws the InvalidFormatException
.
protected String getDefaultPattern(int variantType)Returns the default pattern used for formatting the data based on the
Variant
type and the current locale.
variantType
Variant
data type.
public Object getSpecialObject(int objType)Retrieves the special object associated with a particular formatter. This is a general purpose routine to obtain specific booleans, characters, flags, and so on inside a formatter, but it is completely dependent on the formatter being used.
objType
ItemFormatter.FILLCHARACTER
or ItemFormatter.REPLACECHARACTER
. Fill characters are used to fill empty slots in the string. Replace characters replace fill characters on output.
public void parse(String stringValue, Variant value)Parses a string using the current pattern and produces the appropriate value in the form of a
Variant
.
stringValue
Variant
object which is set to AssignedNull
.
value
Variant
that contains the result. Its type is determined by the variantType
parameter in the class constructor.
public void parse(String stringValue, Variant value, int variantType)Parses a string using the current pattern and produces the appropriate value in the form of a
Variant
.
stringValue
Variant
object which is set to AssignedNull
.
value
Variant
that contains the result.
variantType
Variant
type returned in the value parameter.
public String setPattern(String pattern)Sets the pattern used by this
VariantFormatStr
object to format and parse. See edit/display masks for information about specifying a pattern.
The prior pattern is returned.
pattern
public Object setSpecialObject(int objType, Object obj)Sets the special object associated with a particular formatter. This is a general purpose routine to obtain specific booleans, characters, flags, and so on inside a formatter, but it is completely dependent on the formatter being used.
setSpecialObject()
returns the prior special object, which can be useful for restoring the original value after a temporary alteration.
objType
ItemFormatter.FILLCHARACTER
or ItemFormatter.REPLACECHARACTER
. Fill characters are used to fill empty slots in the string. Replace characters replace fill characters on output.
obj
Object
must match the expected type for the given objType
; do not pass a null object.