本文整理匯總了Java中tec.uom.se.format.SimpleUnitFormat類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleUnitFormat類的具體用法?Java SimpleUnitFormat怎麽用?Java SimpleUnitFormat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleUnitFormat類屬於tec.uom.se.format包,在下文中一共展示了SimpleUnitFormat類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import tec.uom.se.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> result = (energy.multiply(4200)).divide(3600);
// System.out.println(result);
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);
}
示例2: parseUnits
import tec.uom.se.format.SimpleUnitFormat; //導入依賴的package包/類
private Unit<?> parseUnits(String name, String units) {
try {
return SimpleUnitFormat.getInstance().parse(units);
} catch (ParserException e) {
throw new SpecificationException("Unexpected units [" + units + "] for " + name, e);
}
}
示例3: init
import tec.uom.se.format.SimpleUnitFormat; //導入依賴的package包/類
@Before
public void init() {
sut = DefaultQuantityFactory.getInstance(Length.class).create(10,
METRE);
format = EBNFUnitFormat.getInstance();
format2 = SimpleUnitFormat.getInstance();
format2.label(CLDR.CARAT, "ct");
format2.label(CLDR.ACRE, "acr");
format2.label(CLDR.TONNE, "t");
}
示例4: main
import tec.uom.se.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);
Quantity q = Quantities.getQuantity("300 " + Units.DAY.getSymbol());
System.out.println(q);
}
示例5: main
import tec.uom.se.format.SimpleUnitFormat; //導入依賴的package包/類
public static void main(String[] args) {
ServiceProvider.current().getSystemOfUnitsService().getSystemOfUnits("CLDR");
// Unit test = BYTE;
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));
UnitFormat format2 = EBNFUnitFormat.getInstance();
System.out.println(format2.format(FOOT));
System.out.println(format2.format(Units.AMPERE));
System.out.println(format2.format(METER));
System.out.println(format2.format(CENTIMETER));
System.out.println(format2.format(MILLIMETER));
System.out.println(format2.format(INCH));
System.out.println(format2.format(YARD));
System.out.println(format2.format(KILOGRAM));
System.out.println(format2.format(GRAM));
}
示例6: addUnit
import tec.uom.se.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;
}
示例7: addUnit
import tec.uom.se.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;
}
示例8: addUnit
import tec.uom.se.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;
}
示例9: addUnit
import tec.uom.se.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;
}
示例10: addUnit
import tec.uom.se.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
* @return <code>unit</code>.
*/
private static <U extends Unit<?>> U addUnit(U unit, String name, String text) {
if (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;
}