public class TLcdScaleFormat extends Format implements ILcdFormatter, ILcdParser
Formats and parses unitless map scale ratios of the format nominator separator denominator
from and to the double representation of the scale.
The parse method also accepts single values, which are interpreted as 1 separator value
.
Some examples:
TLcdScaleFormat scaleFormat = new TLcdScaleFormat(NumberFormat.getInstance(Locale.US));
String scaleAsString = "1:25,000";
Double scale = scaleFormat.parse(scaleAsString);//0.00004
TLcdMapScale scale = scaleFormat.parseMapScale(scaleAsString);//a TLcdMapScale of 1:25,000
and
TLcdScaleFormat scaleFormat = new TLcdScaleFormat(NumberFormat.getInstance(Locale.US));
Double scale = 0.00004;
String scaleAsString = scaleFormat.format(scale);//"1 : 25,000"
String scaleAsString = scaleFormat.format(new TLcdMapScale(scale));//"1 : 25,000"
The format also parses numbers with common decadic multiple suffixes (k for kilo, m for mega/million, b for billion, g for giga,
t for trillion/tera). For example:
TLcdScaleFormat scaleFormat = new TLcdScaleFormat(NumberFormat.getInstance(Locale.US));
String scaleAsString = "1:25K";
Double scale = scaleFormat.parse(scaleAsString);//0.00004
Format.Field
Constructor and Description |
---|
TLcdScaleFormat()
Creates a new scale format with a default
NumberFormat used to parse and format
the nominator and denominator, and a default separator character (':'). |
TLcdScaleFormat(NumberFormat aNumberFormat)
Creates a new scale format where
aNumberFormat is used to parse and format the
nominator and denominator. |
TLcdScaleFormat(NumberFormat aNumberFormat,
char aSeparator)
Creates a new scale format where
aNumberFormat is used to parse and format the
nominator and denominator. |
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
Double |
parse(String aString)
Parses a given
String and creates a new Object
with the corresponding type/properties. |
TLcdMapScale |
parseMapScale(String aMapScale)
Parses the given map scale string into a
TLcdMapScale instance. |
Double |
parseObject(String aSource) |
Object |
parseObject(String aMapScale,
ParsePosition pos) |
clone, format, formatToCharacterIterator
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
format
public TLcdScaleFormat()
NumberFormat
used to parse and format
the nominator and denominator, and a default separator character (':').public TLcdScaleFormat(NumberFormat aNumberFormat)
aNumberFormat
is used to parse and format the
nominator and denominator. A default separator character is used (':').aNumberFormat
- The number format used for parsing and formatting of the nominator and
denominatorpublic TLcdScaleFormat(NumberFormat aNumberFormat, char aSeparator)
aNumberFormat
is used to parse and format the
nominator and denominator. aSeparator
is used to separate the nominator from the
denominatoraNumberFormat
- The number format used for parsing and formatting of the nominator and
denominatoraSeparator
- The separator char between the nominator and the denominator.
aNumberFormat
must not parse aSeparator
, so e.g.
using a '.' as separator might not work with certain Locale settings.public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) throws IllegalArgumentException
format
in class Format
IllegalArgumentException
public TLcdMapScale parseMapScale(String aMapScale) throws ParseException
TLcdMapScale
instance.aMapScale
- the string containing the map scaleParseException
public Object parseObject(String aMapScale, ParsePosition pos)
parseObject
in class Format
public Double parseObject(String aSource) throws ParseException
parseObject
in class Format
ParseException
public Double parse(String aString) throws IllegalArgumentException
ILcdParser
String
and creates a new Object
with the corresponding type/properties.parse
in interface ILcdParser
aString
- the String
to be parsed.Object
.IllegalArgumentException
- if the String
can't be parsed.