本文整理汇总了Java中javax.measure.Unit类的典型用法代码示例。如果您正苦于以下问题:Java Unit类的具体用法?Java Unit怎么用?Java Unit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Unit类属于javax.measure包,在下文中一共展示了Unit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convert
import javax.measure.Unit; //导入依赖的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: convertKineticLaw
import javax.measure.Unit; //导入依赖的package包/类
public DynamicKineticLaw convertKineticLaw(KineticLaw sbmlKineticLaw) {
if (!sbmlKineticLaw.getMath().toString().equals("NaN")) {
String unitIdentifier = sbmlKineticLaw.getDerivedUnitDefinition().getId();
Unit<?> parameterUnit;
if (unitIdentifier.equalsIgnoreCase("dimensionless") || unitIdentifier.isEmpty()) {
parameterUnit = ONE;
} else {
parameterUnit = units.get(unitIdentifier);
}
logger.debug("Creating kinetic law with expression {} ...", sbmlKineticLaw.getMath().toString());
AppliedExpression appliedExpression = expressionConverter.convertRawExpression(sbmlKineticLaw.getMath(), sbmlKineticLaw.getListOfLocalParameters(), parameterUnit);
return new DynamicKineticLaw(appliedExpression);
} else {
logger.warn("Could not parse a valid expression for this reaction.");
return null;
}
}
开发者ID:cleberecht,项目名称:singa,代码行数:18,代码来源:SBMLKineticLawConverter.java
示例3: convertAssignmentRule
import javax.measure.Unit; //导入依赖的package包/类
public AssignmentRule convertAssignmentRule(org.sbml.jsbml.AssignmentRule sbmlAssignmentRule) {
String unitIdentifier = sbmlAssignmentRule.getDerivedUnitDefinition().getId();
Unit<?> parameterUnit;
if (unitIdentifier.equalsIgnoreCase("dimensionless") || unitIdentifier.isEmpty()) {
parameterUnit = ONE;
} else {
parameterUnit = units.get(unitIdentifier);
}
final AppliedExpression appliedExpression = expressionConverter.convertRawExpression(sbmlAssignmentRule.getMath(), parameterUnit);
final ChemicalEntity targetEntity = entities.get(sbmlAssignmentRule.getVariable());
AssignmentRule assignmentRule = new AssignmentRule(targetEntity, appliedExpression);
// find referenced entities
for (String identifier : entities.keySet()) {
Pattern pattern = Pattern.compile("(\\W|^)(" + identifier + ")(\\W|$)");
Matcher matcher = pattern.matcher(sbmlAssignmentRule.getMath().toString());
if (matcher.find()) {
assignmentRule.referenceChemicalEntityToParameter(identifier, entities.get(identifier));
}
}
return assignmentRule;
}
开发者ID:cleberecht,项目名称:singa,代码行数:22,代码来源:SBMLAssignmentRuleConverter.java
示例4: getSubCounters
import javax.measure.Unit; //导入依赖的package包/类
private List<Counter> getSubCounters(String baseName,
String baseDescription, Unit<?> unit) {
List<Counter> counters = Lists.newArrayList();
for (TimeWindow timeWindow : timeWindows) {
final TimeWindowCounter value = new TimeWindowCounter(timeWindow,
timeSource);
String name = String
.format("%s.%s", baseName, timeWindow.getName());
String description = String.format("%s [%s]", baseDescription,
timeWindow.getName());
PollingMonitoredValue.poll(name, description, registry,
timeWindow.getResolution(), new Supplier<Long>() {
@Override
public Long get() {
return value.get();
}
}, ValueSemantics.FREE_RUNNING, unit);
counters.add(value);
}
return counters;
}
开发者ID:performancecopilot,项目名称:parfait,代码行数:24,代码来源:TimeWindowCounterBuilder.java
示例5: testWithOddUnits
import javax.measure.Unit; //导入依赖的package包/类
@Test
public void testWithOddUnits() {
MassAmount m = new MassAmount(100, USCustomary.POUND);
@SuppressWarnings("unchecked") // we know this creates an acceleration!
Unit<Acceleration> inch_per_square_second = (Unit<Acceleration>)USCustomary.INCH.divide(SI.SECOND).divide(SI.SECOND);
// logger.log(Level.FINER, "Acceleration = " + inch_per_square_second);
logger.log(Level.FINE, String.valueOf(inch_per_square_second));
AccelerationAmount a = new AccelerationAmount(100, inch_per_square_second);
ForceAmount force = NewtonsSecondLaw.calculateForce(m, a);
// assertEquals(867961.6621451874, force.doubleValue(SI.NEWTON), 0.0000000001);
assertEquals(115.21246198, force.doubleValue(SI.NEWTON), 0.0000000001);
// Pound-force (http://en.wikipedia.org/wiki/Pound-force) is a unit for Force in English engineering units and British gravitational units
Unit<Force> poundForce = SI.NEWTON.multiply(4.448222);
// assertEquals(3860886.16071079, force.doubleValue(poundForce), 0.0000000001);
assertEquals(25.900789569405482, force.doubleValue(poundForce), 0.0000000001);
}
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:17,代码来源:NewtonsSecondLawTest.java
示例6: convertUnits
import javax.measure.Unit; //导入依赖的package包/类
public Map<String, Unit<?>> convertUnits(ListOf<UnitDefinition> sbmlUnits) {
Map<String, Unit<?>> units = new HashMap<>();
for (UnitDefinition unitDefinition : sbmlUnits) {
units.put(unitDefinition.getId(), convertUnit(unitDefinition));
}
return units;
}
开发者ID:cleberecht,项目名称:singa,代码行数:8,代码来源:SBMLUnitConverter.java
示例7: convertUnit
import javax.measure.Unit; //导入依赖的package包/类
public Unit<?> convertUnit(UnitDefinition unitDefinition) {
Unit<?> resultUnit = new ProductUnit();
for (org.sbml.jsbml.Unit sbmlUnit : unitDefinition.getListOfUnits()) {
Unit unitComponent = getUnitForKind(sbmlUnit.getKind());
unitComponent = unitComponent.transform(
UnitPrefixes.getUnitPrefixFromScale(sbmlUnit.getScale()).getCorrespondingConverter());
unitComponent = unitComponent.pow((int) sbmlUnit.getExponent());
unitComponent = unitComponent.multiply(sbmlUnit.getMultiplier());
resultUnit = resultUnit.multiply(unitComponent);
}
logger.debug("Parsed unit {},", resultUnit.toString());
return resultUnit;
}
开发者ID:cleberecht,项目名称:singa,代码行数:14,代码来源:SBMLUnitConverter.java
示例8: convertParameter
import javax.measure.Unit; //导入依赖的package包/类
private SimulationParameter<?> convertParameter(String primaryIdentifier, double value, String unit) {
Unit<?> parameterUnit;
if (unit.equalsIgnoreCase("dimensionless") || unit.isEmpty()) {
parameterUnit = ONE;
} else {
parameterUnit = units.get(unit);
}
SimulationParameter<?> simulationParameter = new SimulationParameter<>(primaryIdentifier,
Quantities.getQuantity(value, parameterUnit));
logger.debug("Set parameter {} to {}.", simulationParameter.getIdentifier(), simulationParameter.getQuantity());
return simulationParameter;
}
开发者ID:cleberecht,项目名称:singa,代码行数:13,代码来源:SBMLParameterConverter.java
示例9: convertRawExpression
import javax.measure.Unit; //导入依赖的package包/类
public AppliedExpression convertRawExpression(ASTNode sbmlExpression, ListOf<LocalParameter> additionalParameters, Unit<?> resultUnit) {
String expressionString = replaceFunction(sbmlExpression.toString());
currentExpression = new AppliedExpression(expressionString, resultUnit);
assignLocalParameters(additionalParameters);
assignGlobalParameters(expressionString);
return currentExpression;
}
开发者ID:cleberecht,项目名称:singa,代码行数:8,代码来源:SBMLExpressionConverter.java
示例10: AppliedExpression
import javax.measure.Unit; //导入依赖的package包/类
public AppliedExpression(String expression, Unit<?> resultUnit) {
Parser parser = new Parser();
expressionString = expression;
this.expression = parser.parse(expression);
parameters = new HashMap<>();
this.resultUnit = resultUnit;
}
开发者ID:cleberecht,项目名称:singa,代码行数:8,代码来源:AppliedExpression.java
示例11: getUnitPrefixFromDivisor
import javax.measure.Unit; //导入依赖的package包/类
/**
* Gets the {@link UnitPrefix} from the divisor of a product unit.
*
* @param unit The product unit.
* @return The {@link UnitPrefix}.
*/
public static UnitPrefix getUnitPrefixFromDivisor(Unit<?> unit) {
Matcher divisorMatcher = divisorPattern.matcher(unit.toString());
if (divisorMatcher.find())
return getUnitPrefixFromScale(divisorMatcher.group(1).length() * -1);
return UnitPrefix.NO_PREFIX;
}
开发者ID:cleberecht,项目名称:singa,代码行数:13,代码来源:UnitPrefixes.java
示例12: formatMultidimensionalUnit
import javax.measure.Unit; //导入依赖的package包/类
/**
* Formats a multidimensional unit to a descriptor string.
*
* @param multiDimensionalUnit The multidimensional unit.
* @return The descriptive string for the given unit.
*/
public static String formatMultidimensionalUnit(Unit<?> multiDimensionalUnit) {
StringBuilder sb = new StringBuilder();
sb.append(getUnitPrefixFromDivisor(multiDimensionalUnit).getSymbol());
Map<? extends Unit<?>, Integer> unitsMap = multiDimensionalUnit.getBaseUnits();
for (Unit<?> compoundUnit : unitsMap.keySet()) {
UnitName unitName = UnitPrefixes.getUnitNameFromUnit(compoundUnit);
sb.append(unitName.getSymbol());
}
return sb.toString();
}
开发者ID:cleberecht,项目名称:singa,代码行数:17,代码来源:UnitPrefixes.java
示例13: testParseSimple
import javax.measure.Unit; //导入依赖的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
示例14: testFormatUCUMCIWithPositivePrefix
import javax.measure.Unit; //导入依赖的package包/类
@Test
public void testFormatUCUMCIWithPositivePrefix() {
final UnitFormat format = UCUMFormat.getInstance(CASE_INSENSITIVE);
Unit<Frequency> hertzMultiple;
hertzMultiple = DEKA(HERTZ);
assertEquals("The DEKA prefix didn't work", "DAHZ", format.format(hertzMultiple));
hertzMultiple = HECTO(HERTZ);
assertEquals("The HECTO prefix didn't work", "HHZ", format.format(hertzMultiple));
hertzMultiple = KILO(HERTZ);
assertEquals("The KILO prefix didn't work", "KHZ", format.format(hertzMultiple));
hertzMultiple = MEGA(HERTZ);
assertEquals("The MEGA prefix didn't work", "MAHZ", format.format(hertzMultiple));
hertzMultiple = GIGA(HERTZ);
assertEquals("The GIGA prefix didn't work", "GAHZ", format.format(hertzMultiple));
hertzMultiple = TERA(HERTZ);
assertEquals("The TERA prefix didn't work", "TRHZ", format.format(hertzMultiple));
hertzMultiple = PETA(HERTZ);
assertEquals("The PETA prefix didn't work", "PTHZ", format.format(hertzMultiple));
hertzMultiple = EXA(HERTZ);
assertEquals("The EXA prefix didn't work", "EXHZ", format.format(hertzMultiple));
hertzMultiple = ZETTA(HERTZ);
assertEquals("The ZETTA prefix didn't work", "ZAHZ", format.format(hertzMultiple));
hertzMultiple = YOTTA(HERTZ);
assertEquals("The YOTTA prefix didn't work", "YAHZ", format.format(hertzMultiple));
assertEquals("The KILO prefix didn't work with a product unit", "KM/S",
format.format(KILO(METER).divide(SECOND)));
}
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:39,代码来源:UCUMFormatTable4Test.java
示例15: PollingMonitoredValue
import javax.measure.Unit; //导入依赖的package包/类
/**
* Creates a new {@link PollingMonitoredValue} with the specified polling
* interval.
*
* @param updateInterval
* how frequently the Poller should be checked for updates (may
* not be less than {@link #MIN_UPDATE_INTERVAL}
*/
public PollingMonitoredValue(String name, String description,
MonitorableRegistry registry, int updateInterval, Supplier<T> poller,
ValueSemantics semantics, Unit<?> unit, Scheduler scheduler) {
super(name, description, registry, poller.get(), unit, semantics);
this.poller = poller;
Preconditions.checkState(updateInterval >= MIN_UPDATE_INTERVAL,
"updateInterval is too short.");
TimerTask task = new PollerTask();
SCHEDULED_TASKS.add(task);
scheduler.schedule(new PollerTask(), updateInterval);
}
开发者ID:performancecopilot,项目名称:parfait,代码行数:20,代码来源:PollingMonitoredValue.java
示例16: poll
import javax.measure.Unit; //导入依赖的package包/类
/**
* Convenient factory method to create pollers you don't care about keeping
* – that is, pollers which should be registered and start updating their
* value, but which you don't need to hold a reference to (because you will
* presumably just be modifying the polled source).
*/
public static <T> void poll(String name, String description,
MonitorableRegistry registry, int updateInterval, Supplier<T> poller,
ValueSemantics semantics, Unit<?> unit) {
new PollingMonitoredValue<T>(name, description, registry,
updateInterval, poller, semantics, unit);
}
开发者ID:performancecopilot,项目名称:parfait,代码行数:13,代码来源:PollingMonitoredValue.java
示例17: testParseSimple3
import javax.measure.Unit; //导入依赖的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
示例18: createCounterPair
import javax.measure.Unit; //导入依赖的package包/类
public Counter createCounterPair(Unit<?> unit, String globalCounterName, String threadMetricName,
String threadMetricSuffix, String description) {
MonitoredCounter metric = new MonitoredCounter(globalCounterName, description, registry, unit);
ThreadCounter threadCounter = new ThreadCounter.ThreadMapCounter();
ThreadMetric threadMetric = new ThreadValueMetric(threadMetricName, unit, threadMetricSuffix,
description, threadCounter);
metricSuite.addMetric(threadMetric);
return new CounterPair(metric, threadCounter);
}
开发者ID:performancecopilot,项目名称:parfait,代码行数:11,代码来源:CounterPairFactory.java
示例19: AbstractMonitorable
import javax.measure.Unit; //导入依赖的package包/类
protected AbstractMonitorable(String name, String description, Class<T> type, Unit<?> unit, ValueSemantics semantics) {
this.name = name;
this.description = description;
this.type = type;
this.unit = unit;
this.semantics = semantics;
LOG = LoggerFactory.getLogger("parfait."+name);
}
开发者ID:performancecopilot,项目名称:parfait,代码行数:9,代码来源:AbstractMonitorable.java
示例20: testUnitsUCUM
import javax.measure.Unit; //导入依赖的package包/类
@Test
public void testUnitsUCUM() {
for (Unit<?> u : UCUM.getInstance().getUnits()) {
// try {
// Unit<?> v = format.parse("1/" + u.toString());
LOGGER.log(LOG_LEVEL, String.format("%s @ %s @ %s @ %s", FORMAT_CS.format(u), FORMAT_CI.format(u), FORMAT_PRINT.format(u), u));
// } catch (ParserException pex) {
// logger.log(Level.WARNING, String.format(" %s parsing %s", pex,
// u));
// }
}
}
开发者ID:unitsofmeasurement,项目名称:uom-systems,代码行数:13,代码来源:UnitFormatTest.java
注:本文中的javax.measure.Unit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论