當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。