本文整理汇总了Java中javax.measure.format.UnitFormat类的典型用法代码示例。如果您正苦于以下问题:Java UnitFormat类的具体用法?Java UnitFormat怎么用?Java UnitFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitFormat类属于javax.measure.format包,在下文中一共展示了UnitFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Override
public Unit convert(String value, ConversionContext context) {
String trimmed = requireNonNull(value).trim();
addSupportedFormats(context);
UnitFormat format = ServiceProvider.current().getUnitFormatService().getUnitFormat();
Unit result = null;
try {
result = format.parse(trimmed);
} catch (RuntimeException e) {
result = null; // Give the next converter a change. Read the JavaDoc
// of convert
}
return result;
}
示例2: main
import javax.measure.format.UnitFormat; //导入依赖的package包/类
public static void main(String[] args) {
final UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("CI");
final Unit<Volume> microliter = MetricPrefix.MICRO(Units.LITRE);
System.out.println(unitFormat.format(microliter)); // prints "nst"!
UnitConverter conv = microliter.getConverterTo(UCUM.STERE);
System.out.println(conv);
UnitConverter conv2 = microliter.getConverterTo(Units.CUBIC_METRE);
System.out.println(conv);
final Unit<?> microliter2 = unitFormat.parse("uL");
System.out.println(unitFormat.format(microliter2));
final UnitFormat unitFormat2 = ServiceProvider.current().getUnitFormatService().getUnitFormat("CS");
final Unit<?> microliter3 = unitFormat2.parse("ul");
System.out.println(unitFormat2.format(microliter3));
final Unit<?> invKelvin = unitFormat.parse("1/K");
System.out.println(invKelvin);
}
示例3: testParseUCUMCIWithPositivePrefix
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testParseUCUMCIWithPositivePrefix() {
final UnitFormat format = UCUMFormat.getInstance(CASE_INSENSITIVE);
assertEquals("The DEKA prefix didn't work", DEKA(HERTZ), format.parse("DAHz"));
assertEquals("The HECTO prefix didn't work", HECTO(HERTZ), format.parse("HHz"));
assertEquals("The KILO prefix didn't work", KILO(HERTZ), format.parse("KHz"));
assertEquals("The MEGA prefix didn't work", MEGA(HERTZ), format.parse("MAHz"));
assertEquals("The GIGA prefix didn't work", GIGA(HERTZ), format.parse("GAHz"));
assertEquals("The TERA prefix didn't work", TERA(HERTZ), format.parse("TRHz"));
assertEquals("The PETA prefix didn't work", PETA(HERTZ), format.parse("PTHz"));
assertEquals("The EXA prefix didn't work", EXA(HERTZ), format.parse("EXHz"));
assertEquals("The ZETTA prefix didn't work", ZETTA(HERTZ), format.parse("ZAHz"));
assertEquals("The YOTTA prefix didn't work", YOTTA(HERTZ), format.parse("YAHz"));
assertEquals("The KILO prefix didn't work with a product unit", KILO(METER).divide(SECOND),
format.parse("KM/S"));
}
示例4: main
import javax.measure.format.UnitFormat; //导入依赖的package包/类
public static void main(String[] args) {
ServiceProvider.current().getSystemOfUnitsService().getSystemOfUnits("CLDR");
// Unit test = BYTE; // To initialize the system (lazy loading, otherwise Format is not updated)
Unit x = AbstractUnit.parse("B");
System.out.println(x);
Unit y = AbstractUnit.parse("N");
System.out.println(y);
UnitFormat unitFormat = SimpleUnitFormat.getInstance();
Unit<Information> bit = unitFormat.parse("bit").asType(Information.class);
System.out.println(bit);
Unit<Information> byteU = unitFormat.parse("byte").asType(Information.class);
System.out.println(byteU);
// System.out.println(BYTE.equals(byteU));
}
示例5: getUnitFormat
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Override
public UnitFormat getUnitFormat(String key) {
Objects.requireNonNull(key, "Format name or alias required");
String alias = aliases.get(key.toUpperCase());
if (alias != null && alias.length() > 0) {
return formats.get(alias);
}
return formats.get(key.toUpperCase());
}
示例6: testFormatUCUMCSWithNegativePrefix
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testFormatUCUMCSWithNegativePrefix() {
final UnitFormat format = UCUMFormat.getInstance(CASE_SENSITIVE);
Unit<Frequency> hertzSubmultiple;
hertzSubmultiple = DECI(HERTZ);
assertEquals("The DECI prefix didn't work", "dHz", format.format(hertzSubmultiple));
hertzSubmultiple = CENTI(HERTZ);
assertEquals("The CENTI prefix didn't work", "cHz", format.format(hertzSubmultiple));
hertzSubmultiple = MILLI(HERTZ);
assertEquals("The MILLI prefix didn't work", "mHz", format.format(hertzSubmultiple));
hertzSubmultiple = MICRO(HERTZ);
assertEquals("The MICRO prefix didn't work", "uHz", format.format(hertzSubmultiple));
hertzSubmultiple = NANO(HERTZ);
assertEquals("The NANO prefix didn't work", "nHz", format.format(hertzSubmultiple));
hertzSubmultiple = PICO(HERTZ);
assertEquals("The PICO prefix didn't work", "pHz", format.format(hertzSubmultiple));
hertzSubmultiple = FEMTO(HERTZ);
assertEquals("The FEMTO prefix didn't work", "fHz", format.format(hertzSubmultiple));
hertzSubmultiple = ATTO(HERTZ);
assertEquals("The ATTO prefix didn't work", "aHz", format.format(hertzSubmultiple));
hertzSubmultiple = ZEPTO(HERTZ);
assertEquals("The ZEPTO prefix didn't work", "zHz", format.format(hertzSubmultiple));
hertzSubmultiple = YOCTO(HERTZ);
assertEquals("The YOCTO prefix didn't work", "yHz", format.format(hertzSubmultiple));
assertEquals("The MILLI prefix didn't work with a product unit", "mm/s",
format.format(MILLI(METER).divide(SECOND)));
}
示例7: testFormatUCUMCSWithPositivePrefix
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testFormatUCUMCSWithPositivePrefix() {
final UnitFormat format = UCUMFormat.getInstance(CASE_SENSITIVE);
Unit<Frequency> hertzMultiple;
hertzMultiple = DEKA(HERTZ);
assertEquals("The DEKA prefix didn't work", "daHz", format.format(hertzMultiple));
hertzMultiple = HECTO(HERTZ);
assertEquals("The HECTO prefix didn't work", "hHz", format.format(hertzMultiple));
hertzMultiple = KILO(HERTZ);
assertEquals("The KILO prefix didn't work", "kHz", format.format(hertzMultiple));
hertzMultiple = MEGA(HERTZ);
assertEquals("The MEGA prefix didn't work", "MHz", format.format(hertzMultiple));
hertzMultiple = GIGA(HERTZ);
assertEquals("The GIGA prefix didn't work", "GHz", format.format(hertzMultiple));
hertzMultiple = TERA(HERTZ);
assertEquals("The TERA prefix didn't work", "THz", format.format(hertzMultiple));
hertzMultiple = PETA(HERTZ);
assertEquals("The PETA prefix didn't work", "PHz", format.format(hertzMultiple));
hertzMultiple = EXA(HERTZ);
assertEquals("The EXA prefix didn't work", "EHz", format.format(hertzMultiple));
hertzMultiple = ZETTA(HERTZ);
assertEquals("The ZETTA prefix didn't work", "ZHz", format.format(hertzMultiple));
hertzMultiple = YOTTA(HERTZ);
assertEquals("The YOTTA prefix didn't work", "YHz", format.format(hertzMultiple));
assertEquals("The KILO prefix didn't work with a product unit", "km/s",
format.format(KILO(METER).divide(SECOND)));
}
示例8: testFormatUCUMCIWithNegativePrefix
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testFormatUCUMCIWithNegativePrefix() {
final UnitFormat format = UCUMFormat.getInstance(CASE_INSENSITIVE);
Unit<Frequency> hertzSubmultiple;
hertzSubmultiple = DECI(HERTZ);
assertEquals("The DECI prefix didn't work", "DHZ", format.format(hertzSubmultiple));
hertzSubmultiple = CENTI(HERTZ);
assertEquals("The CENTI prefix didn't work", "CHZ", format.format(hertzSubmultiple));
hertzSubmultiple = MILLI(HERTZ);
assertEquals("The MILLI prefix didn't work", "MHZ", format.format(hertzSubmultiple));
hertzSubmultiple = MICRO(HERTZ);
assertEquals("The MICRO prefix didn't work", "UHZ", format.format(hertzSubmultiple));
hertzSubmultiple = NANO(HERTZ);
assertEquals("The NANO prefix didn't work", "NHZ", format.format(hertzSubmultiple));
hertzSubmultiple = PICO(HERTZ);
assertEquals("The PICO prefix didn't work", "PHZ", format.format(hertzSubmultiple));
hertzSubmultiple = FEMTO(HERTZ);
assertEquals("The FEMTO prefix didn't work", "FHZ", format.format(hertzSubmultiple));
hertzSubmultiple = ATTO(HERTZ);
assertEquals("The ATTO prefix didn't work", "AHZ", format.format(hertzSubmultiple));
hertzSubmultiple = ZEPTO(HERTZ);
assertEquals("The ZEPTO prefix didn't work", "ZOHZ", format.format(hertzSubmultiple));
hertzSubmultiple = YOCTO(HERTZ);
assertEquals("The YOCTO prefix didn't work", "YOHZ", format.format(hertzSubmultiple));
assertEquals("The MILLI prefix didn't work with a product unit", "MM/S",
format.format(MILLI(METER).divide(SECOND)));
}
示例9: testFormatUCUMCIWithPositivePrefix
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testFormatUCUMCIWithPositivePrefix() {
final UnitFormat format = UCUMFormat.getInstance(CASE_INSENSITIVE);
Unit<Frequency> hertzMultiple;
hertzMultiple = DEKA(HERTZ);
assertEquals("The DEKA prefix didn't work", "DAHZ", format.format(hertzMultiple));
hertzMultiple = HECTO(HERTZ);
assertEquals("The HECTO prefix didn't work", "HHZ", format.format(hertzMultiple));
hertzMultiple = KILO(HERTZ);
assertEquals("The KILO prefix didn't work", "KHZ", format.format(hertzMultiple));
hertzMultiple = MEGA(HERTZ);
assertEquals("The MEGA prefix didn't work", "MAHZ", format.format(hertzMultiple));
hertzMultiple = GIGA(HERTZ);
assertEquals("The GIGA prefix didn't work", "GAHZ", format.format(hertzMultiple));
hertzMultiple = TERA(HERTZ);
assertEquals("The TERA prefix didn't work", "TRHZ", format.format(hertzMultiple));
hertzMultiple = PETA(HERTZ);
assertEquals("The PETA prefix didn't work", "PTHZ", format.format(hertzMultiple));
hertzMultiple = EXA(HERTZ);
assertEquals("The EXA prefix didn't work", "EXHZ", format.format(hertzMultiple));
hertzMultiple = ZETTA(HERTZ);
assertEquals("The ZETTA prefix didn't work", "ZAHZ", format.format(hertzMultiple));
hertzMultiple = YOTTA(HERTZ);
assertEquals("The YOTTA prefix didn't work", "YAHZ", format.format(hertzMultiple));
assertEquals("The KILO prefix didn't work with a product unit", "KM/S",
format.format(KILO(METER).divide(SECOND)));
}
示例10: testFormatUCUMPrintWithNegativePrefix
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testFormatUCUMPrintWithNegativePrefix() {
final UnitFormat format = UCUMFormat.getInstance(PRINT);
Unit<Frequency> hertzSubmultiple;
hertzSubmultiple = DECI(HERTZ);
assertEquals("The DECI prefix didn't work", "dHz", format.format(hertzSubmultiple));
hertzSubmultiple = CENTI(HERTZ);
assertEquals("The CENTI prefix didn't work", "cHz", format.format(hertzSubmultiple));
hertzSubmultiple = MILLI(HERTZ);
assertEquals("The MILLI prefix didn't work", "mHz", format.format(hertzSubmultiple));
hertzSubmultiple = MICRO(HERTZ);
assertEquals("The MICRO prefix didn't work", "µHz", format.format(hertzSubmultiple));
hertzSubmultiple = NANO(HERTZ);
assertEquals("The NANO prefix didn't work", "nHz", format.format(hertzSubmultiple));
hertzSubmultiple = PICO(HERTZ);
assertEquals("The PICO prefix didn't work", "pHz", format.format(hertzSubmultiple));
hertzSubmultiple = FEMTO(HERTZ);
assertEquals("The FEMTO prefix didn't work", "fHz", format.format(hertzSubmultiple));
hertzSubmultiple = ATTO(HERTZ);
assertEquals("The ATTO prefix didn't work", "aHz", format.format(hertzSubmultiple));
hertzSubmultiple = ZEPTO(HERTZ);
assertEquals("The ZEPTO prefix didn't work", "zHz", format.format(hertzSubmultiple));
hertzSubmultiple = YOCTO(HERTZ);
assertEquals("The YOCTO prefix didn't work", "yHz", format.format(hertzSubmultiple));
assertEquals("The MILLI prefix didn't work with a product unit", "mm/s",
format.format(MILLI(METER).divide(SECOND)));
}
示例11: testFormatUCUMPrintWithPositivePrefix
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testFormatUCUMPrintWithPositivePrefix() {
final UnitFormat format = UCUMFormat.getInstance(PRINT);
Unit<Frequency> hertzMultiple;
hertzMultiple = DEKA(HERTZ);
assertEquals("The DEKA prefix didn't work", "daHz", format.format(hertzMultiple));
hertzMultiple = HECTO(HERTZ);
assertEquals("The HECTO prefix didn't work", "hHz", format.format(hertzMultiple));
hertzMultiple = KILO(HERTZ);
assertEquals("The KILO prefix didn't work", "kHz", format.format(hertzMultiple));
hertzMultiple = MEGA(HERTZ);
assertEquals("The MEGA prefix didn't work", "MHz", format.format(hertzMultiple));
hertzMultiple = GIGA(HERTZ);
assertEquals("The GIGA prefix didn't work", "GHz", format.format(hertzMultiple));
hertzMultiple = TERA(HERTZ);
assertEquals("The TERA prefix didn't work", "THz", format.format(hertzMultiple));
hertzMultiple = PETA(HERTZ);
assertEquals("The PETA prefix didn't work", "PHz", format.format(hertzMultiple));
hertzMultiple = EXA(HERTZ);
assertEquals("The EXA prefix didn't work", "EHz", format.format(hertzMultiple));
hertzMultiple = ZETTA(HERTZ);
assertEquals("The ZETTA prefix didn't work", "ZHz", format.format(hertzMultiple));
hertzMultiple = YOTTA(HERTZ);
assertEquals("The YOTTA prefix didn't work", "YHz", format.format(hertzMultiple));
assertEquals("The KILO prefix didn't work with a product unit", "km/s",
format.format(KILO(METER).divide(SECOND)));
}
示例12: testParseSimple
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testParseSimple() {
final UnitFormat format = EBNFUnitFormat.getInstance();
try {
Unit<?> u = format.parse("s");
assertEquals("s", u.getSymbol());
assertEquals(SECOND, u);
} catch (ParserException e) {
fail(e.getMessage());
}
}
示例13: testParseSimple1
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testParseSimple1() {
final UnitFormat format = EBNFUnitFormat.getInstance();
try {
Unit<?> u = format.parse("min");
assertEquals("min", u.getSymbol());
assertEquals(MINUTE, u);
} catch (ParserException e) {
fail(e.getMessage());
}
}
示例14: testParseSimple2
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testParseSimple2() {
final UnitFormat format = EBNFUnitFormat.getInstance();
try {
Unit<?> u = format.parse("m");
assertEquals("m", u.getSymbol());
assertEquals(METRE, u);
} catch (ParserException e) {
fail(e.getMessage());
}
}
示例15: testParseSimple3
import javax.measure.format.UnitFormat; //导入依赖的package包/类
@Test
public void testParseSimple3() {
final UnitFormat format = EBNFUnitFormat.getInstance();
try {
Unit<?> u = format.parse("kg");
assertEquals("kg", u.getSymbol());
assertEquals(KILOGRAM, u);
} catch (ParserException e) {
fail(e.getMessage());
}
}