当前位置: 首页>>代码示例>>Java>>正文


Java UnitFormat.parse方法代码示例

本文整理汇总了Java中javax.measure.format.UnitFormat.parse方法的典型用法代码示例。如果您正苦于以下问题:Java UnitFormat.parse方法的具体用法?Java UnitFormat.parse怎么用?Java UnitFormat.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.measure.format.UnitFormat的用法示例。


在下文中一共展示了UnitFormat.parse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:apache,项目名称:incubator-tamaya-sandbox,代码行数:19,代码来源:UnitConverter.java

示例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);
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:20,代码来源:UCUMFormatDemo.java

示例3: 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());
	}
}
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:12,代码来源:UnitFormatTest.java

示例4: 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());
	}
}
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:12,代码来源:UnitFormatTest.java

示例5: 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());
	}
}
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:12,代码来源:UnitFormatTest.java

示例6: 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());
	}
}
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:12,代码来源:UnitFormatTest.java

示例7: main

import javax.measure.format.UnitFormat; //导入方法依赖的package包/类
public static void main(String[] args) {

      final UnitFormat ucumFormat = UCUMFormat.getInstance(Variant.CASE_SENSITIVE);
      final UnitFormat ucumFormatPrint = UCUMFormat.getInstance(Variant.PRINT);
      Unit<?> glomerular = ucumFormat.parse("mL/min/((173/100).m2)");
       System.out.println(glomerular);
       System.out.println(ucumFormat.format(glomerular));
       System.out.println(ucumFormatPrint.format(glomerular));
      ucumFormat.parse(ucumFormat.format(glomerular));
    }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:11,代码来源:ConversionError.java

示例8: main

import javax.measure.format.UnitFormat; //导入方法依赖的package包/类
public static void main(String[] args) {
UnitFormat unitFormat = ServiceProvider.current().getUnitFormatService().getUnitFormat("UCUM");
System.out.println(unitFormat);

UnitFormat cs = ServiceProvider.current().getUnitFormatService().getUnitFormat("CS");
System.out.println(cs);
Unit<?> unit = cs.parse("m/s");
System.out.println(unit);
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:10,代码来源:UCUMServiceDemo.java

示例9: main

import javax.measure.format.UnitFormat; //导入方法依赖的package包/类
public static void main(String[] args) {

UnitFormat format = ServiceProvider.current().getUnitFormatService().getUnitFormat();
Unit mg_per_25g = format.parse("mg/25/g");
format.label(mg_per_25g, "bw25g");
Quantity mg_per_25g_Bodyweight = Quantities.getQuantity(new BigDecimal("1"), mg_per_25g);

System.out.println(mg_per_25g_Bodyweight.toString()); 
// Without label the output is 1 kg/2.5E7/g
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:11,代码来源:BodyWeightDemo.java

示例10: main

import javax.measure.format.UnitFormat; //导入方法依赖的package包/类
public static void main(String[] args) {
	Unit<Mass> atomicMassUnit = ATOMIC_MASS_UNIT;
	System.out.println(atomicMassUnit.getSymbol());

	Quantity<Mass> mass = (Quantity<Mass>) Quantities.getQuantity(10, atomicMassUnit);
	System.out.println(mass);

	Quantity<Mass> massInKg = mass.to(Units.KILOGRAM);
	System.out.println(massInKg);

	UnitFormat cs = UCUMFormat.getInstance(Variant.CASE_SENSITIVE);
	Unit<?> unit = cs.parse("m/s");
	System.out.println(unit);

	// unit = format.parse("m^1*s^-1");
	// System.out.println(unit);

	System.out.println(UCUM.PARSEC);
	UnitFormat print = UCUMFormat.getInstance(Variant.PRINT);
	System.out.println(print.format(UCUM.PARSEC));

	Unit<Frequency> hz = UCUM.HERTZ;
	System.out.println(hz);
	System.out.println(hz.getBaseUnits());
	System.out.println(print.format(UCUM.HERTZ));

	Unit<Frequency> khz = KILO(hz);
	System.out.println(khz.getBaseUnits());

	unit = cs.parse("Hz");
	System.out.println(unit);
	unit = cs.parse("kHz");
	System.out.println(unit);

//	UnitFormat ebnf = EBNFUnitFormat.getInstance();
//	unit = ebnf.parse("MHz");
//	System.out.println(unit);
	
	Quantity<Volume> oneLiter = Quantities.getQuantity(1, LITER);
	System.out.println(oneLiter.to(LITER_DM3).getValue());
    }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:42,代码来源:UCUMDemoSE.java


注:本文中的javax.measure.format.UnitFormat.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。