I'm using jscience to parse some units for me:
Unit<?> meter = Unit.valueOf("m");
System.out.println(meter);
Unit<?> foot = Unit.valueOf("ft");
System.out.println(foot);
This prints out :
m
ft
I'd like it to print out
metre
foot
Or something like this. In reality I'm actually reading in these unit strings, I have no control over what the user types, so I'd expect some to type "m", some to type "metre". When displaying it back, I'd like to always display it back as "Metre".
[Limitation]
The program is a large data storage program storing many different types of quantities. The user can store any quantity of any dimension (as long as it's defined in UCUM).
You can use the
UnitFormatclass to specify how these classes get printed. Use thelabelmethod to specify the name, and thealiasmethod to assist with parsing.Output:
Note that if you remove the
instance.labelline from this program, the output is:The default value is the short form that you describe in your original post. I assume that the default values are the short form values described by UCUM, but I haven't actually checked.