本文整理汇总了Java中javax.measure.unit.UnitFormat类的典型用法代码示例。如果您正苦于以下问题:Java UnitFormat类的具体用法?Java UnitFormat怎么用?Java UnitFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitFormat类属于javax.measure.unit包,在下文中一共展示了UnitFormat类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: format
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Appendable format(Amount arg0, Appendable arg1)
throws IOException {
if (arg0.getUnit() instanceof Currency)
return formatMoney(arg0, arg1);
if (arg0.isExact()) {
TypeFormat.format(arg0.getExactValue(), arg1);
arg1.append(' ');
return UnitFormat.getInstance().format(arg0.getUnit(), arg1);
}
double value = arg0.getEstimatedValue();
double error = arg0.getAbsoluteError();
int log10Value = (int) MathLib.floor(MathLib.log10(MathLib
.abs(value)));
int log10Error = (int) MathLib.floor(MathLib.log10(error));
int digits = log10Value - log10Error - 1; // Exact digits.
boolean scientific = (MathLib.abs(value) >= 1E6)
|| (MathLib.abs(value) < 1E-6);
boolean showZeros = true;
TypeFormat.format(value, digits, scientific, showZeros, arg1);
arg1.append(' ');
return UnitFormat.getInstance().format(arg0.getUnit(), arg1);
}
开发者ID:jgaltidor,项目名称:VarJ,代码行数:26,代码来源:AmountFormat.java
示例2: toTargetValue
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
/**
* Convert to target value. You can override this if you have your own format.
*
* @param expectedType
* @param inLanguage
* @param value
* @param style
* @return
*/
public Object toTargetValue(String expectedType, String inLanguage, String value, ConversationStyle style) {
final Locale realLocale = Locale.forLanguageTag(inLanguage);
switch (expectedType) {
case "xsd:string":
return value;
case "xsd:integer":
return Integer.parseInt(value);
case "xs:date":
final LocalDate localDate = DateTimeFormat.longDate().withLocale(Locale.forLanguageTag(inLanguage)).parseLocalDate(value);
return localDate;
case "yago:yagoQuantity":
final MeasureFormat measureFormat = MeasureFormat.getInstance(NumberFormat.getNumberInstance(realLocale), UnitFormat.getInstance(realLocale));
// final DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(Locale.forLanguageTag(inLanguage));
final String tweakedMeasure = value.replaceFirst("^([-]?[0-9]+[.,]?[0-9]*)\\s*", "$1 ");
return measureFormat.parse(tweakedMeasure, new ParsePosition(0));
// .replace(Character.toString(decimalFormat.getDecimalFormatSymbols().getDecimalSeparator()), "!DECIMAL!")
// .replace(Character.toString(decimalFormat.getDecimalFormatSymbols().getGroupingSeparator()), "")
// .replace("!DECIMAL!", ".");
//return Measure.valueOf(tweakedMeasure);
case "yago:wordnet_unit_of_measurement_113583724":
return Unit.valueOf(value);
default:
throw new ReasonerException("Unsupported type: " + expectedType);
}
}
开发者ID:lumenrobot,项目名称:lumen,代码行数:35,代码来源:PromptTask.java
示例3: JEVisUnitImp
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
public JEVisUnitImp(org.jevis.commons.ws.json.JsonUnit json) {
Gson gson = new Gson();
logger.trace("Init Unit: {}", gson.toJson(json));
_label = json.getLabel();
_prefix = UnitManager.getInstance().getPrefix(json.getPrefix(), Locale.getDefault());
ParsePosition pp = new ParsePosition(0);
_unit = UnitFormat.getInstance().parseObject(json.getFormula(), pp);
try{
UnitManager.getInstance().getUnitWithPrefix(_unit, getPrefix());
_unit.toString();
}catch(Exception ex){
System.out.println("Warning! Could not parse unit from json: '" + gson.toJson(json) + "' " + ex.getMessage());
_unit = Unit.ONE;
_label = "Unknown";
_prefix = Prefix.NONE;
}
}
开发者ID:OpenJEVis,项目名称:JECommons,代码行数:21,代码来源:JEVisUnitImp.java
示例4: Convert
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
public Convert(Map<String, Map<String, Map<String, String>>> readerUnits,
Map<String, Map<String, Map<String, String>>> writerUnits, Default def) {
//TODO generate custom units from manifest.json automatically
UnitFormat.getInstance().label(NonSI.E.divide(18.222615), "efact");
UnitFormat.getInstance().label(KILO(JOULE.times(cal)), "kcal");
UnitFormat.getInstance().label(JOULE.times(cal), "cal");
this.readerUnits = readerUnits;
this.writerUnits = writerUnits;
this.def = def;
}
开发者ID:ccaleman,项目名称:MDConverter,代码行数:11,代码来源:Convert.java
示例5: printConfluenceTableRow
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
private void printConfluenceTableRow(Element refUnitElement) {
Unit unit = parseUnitElement(refUnitElement);
String unitString = null;
if (unit == null) {
unitString = "(x)";
} else if (unit == Unit.ONE) {
unitString = "Dimensionless";
} else {
unitString = UnitFormat.getUCUMInstance().format(unit);
}
System.out.println("| *"+ refUnitElement.getAttribute("Name")+"* | "+refUnitElement.getAttribute("Abbrev")+" | "+unitString+" |");
}
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:14,代码来源:TestUDict.java
示例6: newTestFormat
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
public static UnitFormat newTestFormat() {
DefaultFormat format = new DefaultFormat() {
private static final long serialVersionUID = -1345662241285090481L;
};
initializeUnitFormat(format);
return format;
}
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:8,代码来源:TestUnitFormatCreator.java
示例7: init
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
public static void init() {
UnitFormat format = UnitFormat.getInstance();
// Possible usage
// format.label(arg0, arg1);
format.label(NonSI.BYTE, "B");
format.label(SI.KILO(NonSI.BYTE), "kB");
format.label(SI.MEGA(NonSI.BYTE), "MB");
format.label(SI.GIGA(NonSI.BYTE), "GB");
format.label(SI.TERA(NonSI.BYTE), "TB");
format.label(SI.PETA(NonSI.BYTE), "PB");
}
开发者ID:SENSIDL-PROJECT,项目名称:SensIDL,代码行数:13,代码来源:NonSILabels.java
示例8: labelCurrency
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
private void labelCurrency(String symbol, Currency curr) {
//String label = market.getCurrencyLabels().get(cSymbol);
String label = props.getProperty(symbol, "");
if (label != null && label.length()>0) {
UnitFormat.getInstance().label(curr, label);
}
}
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:8,代码来源:PortfolioController.java
示例9: NumberUnit
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
private NumberUnit(NumberFormat numberFormat, UnitFormat unitFormat) {
_numberFormat = numberFormat;
_unitFormat = unitFormat;
}
开发者ID:jgaltidor,项目名称:VarJ,代码行数:5,代码来源:MeasureFormat.java
示例10: onStateChanged
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
@Override
public void onStateChanged(ActivityState previous, ActivityState current, Locale locale, InteractionSession session) throws Exception {
super.onStateChanged(previous, current, locale, session);
if (ActivityState.PENDING == previous && ActivityState.ACTIVE == current) {
final List<UtterancePattern> localizedExpressions = expressions.stream()
.filter(it -> null == it.getInLanguage() || locale.equals(Locale.forLanguageTag(it.getInLanguage())))
.collect(Collectors.toList());
Preconditions.checkState(!localizedExpressions.isEmpty(),
"Cannot get %s expression for affirmation '%s' from %s expressions: %s",
locale.toLanguageTag(), getPath(), expressions.size(), expressions);
final UtterancePattern expression = localizedExpressions.get(RandomUtils.nextInt(0, localizedExpressions.size()));
// interpolate with in-slots
final String pattern = expression.getPattern();
StringBuffer sb = new StringBuffer();
final Pattern SLOT_PLACEHOLDER = Pattern.compile("\\{([a-z0-9_]+)\\}", Pattern.CASE_INSENSITIVE);
final Matcher matcher = SLOT_PLACEHOLDER.matcher(pattern);
while (matcher.find()) {
matcher.appendReplacement(sb, "");
final String slotId = matcher.group(1);
final Object slotValue = getInSlot(slotId).getLast();
log.debug("in-slot {}.{} = {}", getPath(), slotId, slotValue);
final String ssmlValue;
if (slotValue instanceof Measure) {
final MeasureFormat measureFormat = MeasureFormat.getInstance(NumberFormat.getNumberInstance(locale), UnitFormat.getInstance(locale));
ssmlValue = measureFormat.format(slotValue);
} else if (slotValue instanceof LocalDate) {
ssmlValue = DateTimeFormat.longDate().withLocale(locale).print((LocalDate) slotValue);
} else if (slotValue instanceof LocalTime) {
ssmlValue = DateTimeFormat.shortTime().withLocale(locale).print((LocalTime) slotValue);
} else if (slotValue instanceof DateTime) {
ssmlValue = DateTimeFormat.longDateTime().withLocale(locale).print((DateTime) slotValue);
} else {
ssmlValue = String.valueOf(slotValue);
}
sb.append(ssmlValue);
}
matcher.appendTail(sb);
final String result = sb.toString();
log.info("'{}' requesting CommunicateAction: {}", getPath(), result);
final CommunicateAction communicateAction = new CommunicateAction(locale, result, null);
communicateAction.setUsedForSynthesis(true);
getPendingCommunicateActions().add(communicateAction);
session.complete(this, locale);
}
}
开发者ID:lumenrobot,项目名称:lumen,代码行数:51,代码来源:AffirmationTask.java
示例11: getUnitFormat
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
public static UnitFormat getUnitFormat() {
return EnsembleFormat.INSTANCE;
}
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:4,代码来源:EnsembleUnitFormat.java
示例12: initializeUnitFormat
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
private static void initializeUnitFormat(UnitFormat unitFormat) {
unitFormat.alias(SI.SECOND, "sec");
unitFormat.alias(SI.SECOND, "seconds");
unitFormat.alias(SI.MILLI(SI.SECOND).times(5.1), "incs");
unitFormat.alias(SI.NEWTON.times(SI.METER), "Nm");
unitFormat.alias(SI.AMPERE, "amps");
unitFormat.alias(SI.AMPERE, "amp");
unitFormat.alias(SI.OHM, "ohms");
unitFormat.alias(NonSI.BYTE, "bytes");
unitFormat.alias(SI.RADIAN, "radian");
unitFormat.alias(SI.RADIAN, "rad");
unitFormat.alias(SI.RADIAN.pow(-1), "curvature");
unitFormat.alias(NonSI.DEGREE_ANGLE, "deg");
unitFormat.alias(SI.CELSIUS, "degC");
unitFormat.alias(SI.WATT, "watts");
unitFormat.alias(Unit.ONE, "samples");
unitFormat.alias(Unit.ONE, "count");
unitFormat.alias(Unit.ONE, "cells");
unitFormat.alias(Unit.ONE, "records");
unitFormat.alias(Unit.ONE, "images");
unitFormat.alias(Unit.ONE, "datasets");
unitFormat.alias(Unit.ONE, "instances");
unitFormat.alias(Unit.ONE, "iterations");
unitFormat.alias(Unit.ONE, "features");
unitFormat.alias(Unit.ONE, "pyramid");
unitFormat.alias(Unit.ONE, "slot");
unitFormat.alias(Unit.ONE, "slots");
unitFormat.alias(Unit.ONE, "levels");
unitFormat.alias(Unit.ONE, "buffers");
unitFormat.alias(Unit.ONE, "failures");
unitFormat.alias(Unit.ONE, "parameters");
unitFormat.alias(Unit.ONE, "points");
unitFormat.alias(Unit.ONE, "entries");
unitFormat.alias(Unit.ONE, "errors");
unitFormat.alias(Unit.ONE, "states");
unitFormat.alias(Unit.ONE, "magnitude");
unitFormat.alias(Unit.ONE, "counts");
unitFormat.alias(Unit.ONE, "stages");
unitFormat.alias(Unit.ONE, "segments");
unitFormat.alias(Unit.ONE, "flushes");
unitFormat.alias(Unit.ONE, "counts");
}
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:51,代码来源:TestUnitFormatCreator.java
示例13: setFormula
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
@Override
public void setFormula(String formula) {
ParsePosition pp = new ParsePosition(0);
_unit = UnitFormat.getInstance().parseObject(formula, pp);
}
开发者ID:OpenJEVis,项目名称:JECommons,代码行数:6,代码来源:JEVisUnitImp.java
示例14: Currency
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
/**
* Creates the currency unit for the given currency code.
* See the <a href="http://www.bsi-global.com/iso4217currency"> ISO 4217
* maintenance agency</a> for more information, including a table of
* currency codes.
*
* @param code the ISO-4217 code of the currency (e.g.
* <code>"EUR", "USD", "JPY"</code>).
* @throws IllegalArgumentException if the specified code is not an ISO-4217
* code.
*/
public Currency(String code) {
_toBaseUnit = new Converter(code, false);
UnitFormat.getInstance().label(this, code);
}
开发者ID:jgaltidor,项目名称:VarJ,代码行数:16,代码来源:Currency.java
示例15: getInstance
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
/**
* Returns the measure format using the specified number format and
* unit format (the number and unit are separated by a space).
*
* @param numberFormat the number format.
* @param unitFormat the unit format.
* @return the corresponding format.
*/
public static MeasureFormat getInstance(NumberFormat numberFormat,
UnitFormat unitFormat) {
return new NumberUnit(numberFormat, unitFormat);
}
开发者ID:jgaltidor,项目名称:VarJ,代码行数:13,代码来源:MeasureFormat.java
示例16: emit
import javax.measure.unit.UnitFormat; //导入依赖的package包/类
/**
* Returns a string representation of the given Unit for the given locale.
*
* @param unit The Unit to be converted to a string.
* @param locale The locale to use when converting the Unit to a string.
* @return A string representation of the given Unit for the given locale.
*/
public static String emit(Unit unit, Locale locale) {
return UnitFormat.getInstance(LocaleHelper.normalize(locale)).format(unit);
}
开发者ID:Permafrost,项目名称:TundraMeasure.java,代码行数:11,代码来源:UnitHelper.java
注:本文中的javax.measure.unit.UnitFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论