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


Java SimpleUnitFormat类代码示例

本文整理汇总了Java中tec.units.ri.format.SimpleUnitFormat的典型用法代码示例。如果您正苦于以下问题:Java SimpleUnitFormat类的具体用法?Java SimpleUnitFormat怎么用?Java SimpleUnitFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleUnitFormat类属于tec.units.ri.format包,在下文中一共展示了SimpleUnitFormat类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的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));
    }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:18,代码来源:CLDRFormatDemo.java

示例2: main

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Quantity<Volume> volume = Quantities.getQuantity(1000, Units.LITRE);
		Quantity<Temperature> temperature = Quantities.getQuantity(20, Units.KELVIN);
		Quantity<Energy> energy = (Quantity<Energy>) volume.multiply(temperature);
		//Quantity<Energy> energy = volume.multiply(temperature).asType(Energy.class); asType won't work here
		Quantity<Energy> result = (energy.multiply(4200)).divide(3600);
		Unit<Energy> WATTHOUR = result.getUnit();
//		SimpleUnitFormat.getInstance().label(WATTHOUR, "Wh");
//		System.out.println(result);
		Quantity<Energy> kwH = result.to(KILO(WATTHOUR));
		SimpleUnitFormat.getInstance().label(KILO(WATTHOUR), "KWh");
		System.out.println(kwH);
		Quantity<Power> kiloWatt = Quantities.getQuantity(9.5, KILO(Units.WATT));
		Quantity<Time> time =  (Quantity<Time>) kwH.divide(kiloWatt);
		SimpleUnitFormat.getInstance().label(time.getUnit(), "h");
		System.out.println(time);
	}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:19,代码来源:HeatRequirementDemo.java

示例3: init

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
@Before
	public void init() {
		sut = DefaultQuantityFactory.getInstance(Length.class).create(10,
				METRE);
		
//		format = EBNFUnitFormat.getInstance();
		format2 = SimpleUnitFormat.getInstance();
		
//		format.label(SI.BEL, "B");
		format2.label(CLDR.CARAT, "ct");
		format2.label(CLDR.ACRE, "ac");
		format2.label(CLDR.TONNE, "t");
	}
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:14,代码来源:UnitFormatTest.java

示例4: main

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
public static void main(String... args) {
    SimpleUnitFormat.getInstance().alias(USCustomary.MILE, "mile");
    
    Unit u = SimpleUnitFormat.getInstance().parse("mile");
    System.out.println(u);
    Unit v = SimpleUnitFormat.getInstance().parse("mi");
    System.out.println(v);
}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:9,代码来源:CommonFormatDemo.java

示例5: main

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
public static void main(String... args) {
	Quantity<Length> len = Quantities.getQuantity(10, IndianPrefix.LAKH(Units.METRE));
	System.out.println(len);
	Quantity<Mass> kg = Quantities.getQuantity(50, KILO(Units.GRAM));
	System.out.println(kg);
	
	System.out.println(Quantities.getQuantity(3.3, LITER).toString());
	Quantity<Volume> nl = Quantities.getQuantity(3.3, NANO(LITER));
	System.out.println(nl.toString());
	//UnitFormat format = EBNFUnitFormat.getInstance();
	UnitFormat format = SimpleUnitFormat.getInstance();
	System.out.println(format.format(nl.getUnit()));
}
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:14,代码来源:CommonPrefixDemo.java

示例6: beforeClass

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
@BeforeClass
   public static void beforeClass() {
SimpleUnitFormat.getInstance().label(Units.CELSIUS, "Celsius");
Main.main(null);
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:6,代码来源:MeasurementControllerIntegrationTest.java

示例7: addUnit

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
/**
    * Adds a new unit not mapped to any specified quantity type and puts a text
    * as symbol or label.
    *
    * @param unit
    *            the unit being added.
    * @param name
    *            the string to use as name
    * @param text
    *            the string to use as label or symbol
    * @param isLabel
    *            if the string should be used as a label or not
    * @return <code>unit</code>.
    */
   private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) {
if (isLabel) {
    SimpleUnitFormat.getInstance().label(unit, text);
}
if (name != null && unit instanceof AbstractUnit) {
    return Helper.addUnit(INSTANCE.units, unit, name);
} else {
    INSTANCE.units.add(unit);
}
return unit;
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:26,代码来源:CLDR.java

示例8: addUnit

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
/**
    * Adds a new unit not mapped to any specified quantity type and puts a text
    * as symbol or label.
    *
    * @param unit
    *            the unit being added.
    * @param name
    *            the string to use as name
    * @param text
    *            the string to use as label or symbol
    * @param isLabel
    *            if the string should be used as a label or not
    * @return <code>unit</code>.
    */
   private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) {
if (isLabel && text != null) {
    SimpleUnitFormat.getInstance().label(unit, text);
}
if (name != null && unit instanceof AbstractUnit) {
    return Helper.addUnit(INSTANCE.units, unit, name);
} else {
    INSTANCE.units.add(unit);
}
return unit;
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:26,代码来源:NonSI.java

示例9: addUnit

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
/**
 * Adds a new unit not mapped to any specified quantity type and puts a text
 * as symbol or label.
 *
 * @param unit
 *            the unit being added.
 * @param name
 *            the string to use as name
 * @param text
 *            the string to use as label or symbol
 * @param isLabel
 *            if the string should be used as a label or not
 * @return <code>unit</code>.
 */
private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) {
	if (isLabel) {
		SimpleUnitFormat.getInstance().label(unit, text);
	}
	if (name != null && unit instanceof AbstractUnit) {
		return Helper.addUnit(INSTANCE.units, unit, name);
	} else {
		INSTANCE.units.add(unit);
	}
	return unit;
}
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:26,代码来源:USCustomary.java

示例10: addUnit

import tec.units.ri.format.SimpleUnitFormat; //导入依赖的package包/类
/**
 * Adds a new unit not mapped to any specified quantity type and puts a text
 * as symbol or label.
 *
 * @param unit
 *            the unit being added.
 * @param name
 *            the string to use as name
 * @param text
 *            the string to use as label or symbol
 * @param isLabel
 *            if the string should be used as a label or not
 * @return <code>unit</code>.
 */
private static <U extends Unit<?>> U addUnit(U unit, String name, String text, boolean isLabel) {
	if (isLabel) {
	    SimpleUnitFormat.getInstance().label(unit, text);
	}
	if (name != null && unit instanceof AbstractUnit) {
	    return Helper.addUnit(INSTANCE.units, unit, name);
	} else {
	    INSTANCE.units.add(unit);
	}
	return unit;
}
 
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:26,代码来源:Imperial.java


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