本文整理汇总了Java中org.jscience.physics.amount.Amount.rangeOf方法的典型用法代码示例。如果您正苦于以下问题:Java Amount.rangeOf方法的具体用法?Java Amount.rangeOf怎么用?Java Amount.rangeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jscience.physics.amount.Amount
的用法示例。
在下文中一共展示了Amount.rangeOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean update() {
Unit unit = null;
long totalExact = 0;
double totalMin = 0;
double totalMax = 0;
boolean inexact = false;
boolean useCachedValue = true;
Amount newValue = null;
for (Dependency previous : getPrevious()) {
Amount value = (Amount) previous.getValue();
if (value == null || ((Double)value.getEstimatedValue()).isNaN()) {
continue;
}
if (unit == null) {
unit = value.getUnit();
newValue = value;
} else {
value = value.to(unit);
if ((value.getMinimumValue() != 0) || (value.getMaximumValue() != 0)) {
useCachedValue = false;
}
}
if (value.isExact()) {
long exact = value.getExactValue();
long sumLong = totalExact + exact;
double sumDouble = ((double)totalExact) + ((double)exact);
if (sumLong == sumDouble) {
totalExact = sumLong;
} else {
inexact = true;
totalMin += value.getMinimumValue();
totalMax += value.getMaximumValue();
}
} else {
inexact = true;
totalMin += value.getMinimumValue();
totalMax += value.getMaximumValue();
}
}
if (!useCachedValue) {
if (inexact) {
totalMin += totalExact;
totalMax += totalExact;
newValue = Amount.rangeOf(totalMin, totalMax, unit);
} else {
newValue = AmountUtils.toAmount(totalExact, unit);
}
}
Amount oldValue = (Amount) getValue();
if (!equals(oldValue, newValue)) {
setValue(newValue);
return true;
}
return false;
}