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


Java Amount.isExact方法代码示例

本文整理汇总了Java中org.jscience.physics.amount.Amount.isExact方法的典型用法代码示例。如果您正苦于以下问题:Java Amount.isExact方法的具体用法?Java Amount.isExact怎么用?Java Amount.isExact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jscience.physics.amount.Amount的用法示例。


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

示例1: hashCode

import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
/**
 * Return a hash code for this amount, to match with the following equals method. 
 * 
 * @param amount
 * @return
 */
public static int hashCode(Amount amount) {
	if (amount == null) {
		return 0;
	}
	if (amount.isExact()) {
		Unit unit = amount.getUnit();
		if (amount.getExactValue() == 0) {
			Dimension dimension = unit.getDimension();
			return dimension.hashCode();
		}
		Unit standardUnit = unit.getStandardUnit();
		Amount amount2 = amount.to(standardUnit);
		return (int)amount2.getExactValue();
	}
	return 0;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:23,代码来源:AmountUtils.java

示例2: equals

import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
/**
 * This utility method will return true in the case where two things have the same dimension and are both zero, regardless of
 * the unit of each amount.
 * 
 * NOTE: does not currently work for non-zero based dimensions such
 * as temperature, where zero Celsius and zero Kelvin are different.
 * 
 * @param <Q>
 * @param q1
 * @param q2
 * @return boolean
 */
public static <Q extends Quantity> boolean equals(Amount<Q> q1, Amount<Q> q2) {
	if (q1 == null) {
		return (q2 == null);
	}
	if (q1.isExact() && q2.isExact()) {
		if (q1.getExactValue() == 0 && (q2.getExactValue() == 0)) {
			Dimension q1dimension = q1.getUnit().getDimension();
			Dimension q2dimension = q2.getUnit().getDimension();
			return q1dimension.equals(q2dimension);
		}
		Amount q3 = q1.to(q2.getUnit());
		return q3.approximates(q2);
	}
	return q1.equals(q2);
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:28,代码来源:AmountUtils.java

示例3: getNumericValue

import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
/**
 * This utility method can be used to get a single numerical value for
 * an amount.  In the case of a an exact amount, this will be the exact value.
 * In the case of an inexact amount, this will be the estimated value, or an
 * adjusted version thereof to maintain the following property:
 * 
 * AmountUtils.getNumericValue(Amount.valueOf(n, Unit.ONE)) should return n
 *       
 * @param amount
 * @return the value of the amount, a Long or a Double (never null)
 */
public static Number getNumericValue(Amount amount) {
	if (amount.isExact()) {
		return amount.getExactValue();
	}
	double relativeError = amount.getRelativeError();
	double value;
	if (relativeError < ERROR_LIMIT) {
		value = amount.getMaximumValue();
		if (value < 0) {
			// for values less than zero, use the minimum value instead
			value = amount.getMinimumValue();
		} else if (amount.getMinimumValue() <= 0) {
			// if the value is zero or above and the minimum is zero or below, zero it is!
			return 0L;
		}
	} else {
		value = amount.getEstimatedValue();
	}
	if (value == (long)value) {
		return (long)value;
	}
	return value;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:35,代码来源:AmountUtils.java

示例4: queueNodeParameterObject

import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
/**
 * Sets the value of a parameter of the node in europa.  Europa should
 * already know about this node. 
 * 
 * @param node
 * @param name the name of the parameter to set
 * @param value the value of the parameter
 */
private boolean queueNodeParameterObject(EPlanElement node, String name, Object value) {
	// TODO: Cache values to prevent setting values that haven't changed.
	if (value instanceof Boolean) {
		return queueNodeParameterValue(node, name, ((Boolean)value).booleanValue());
	} else if (value instanceof Float) {
		return queueNodeParameterValue(node, name, ((Float)value).floatValue());
	} else if (value instanceof Double) {
		return queueNodeParameterValue(node, name, ((Double)value).floatValue());
	} else if (value instanceof Integer) {
		return queueNodeParameterValue(node, name, ((Integer)value).intValue());
	} else if (value instanceof Long) {
		return queueNodeParameterValue(node, name, ((Long)value).longValue());
	} else if (value instanceof String) {
		return queueNodeParameterValue(node, name, (String)value);
	} else if (value instanceof EEnumLiteral) {
		return queueNodeParameterValue(node, name, ((EEnumLiteral)value).getName());
	} else if (value instanceof Amount<?>) {
		Amount<?> val = (Amount<?>) value;
		if (val.isExact()) {
			long intVal = val.getExactValue();
			return queueNodeParameterValue(node, name, intVal);
		} else {
			Double floatVal = val.getEstimatedValue();
			return queueNodeParameterValue(node, name, floatVal.floatValue());
		}
	} else {
	    return false;
	}
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:38,代码来源:EuropaQueuer.java

示例5: 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;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:58,代码来源:SummingDependency.java

示例6: writeConstant

import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
protected void writeConstant(PrintStream out, Constant constant) {
	// Do nothing if no activity uses the constant.
	if (!formulaUsesIdentifier(null, NDDLUtil.escape(constant.getName())))
		return;
	// Could include constant comments, but clutters.
	// if (constant.getNote() != null)
	// out.printf("/* %s */\n", constant.getNote());
	Object value = constant.getValue();
	// What to do about units? Have to assume they are ok for the
	// compat resource formulas, but show them as comments.
	if (value instanceof Amount<?>) {
		try {
			// Remark: For mslice, all the Amount constants seem
			// to be durations measured in seconds.
			Amount<?> val = (Amount<?>) value;
			if (val.isExact()) {
				out.printf("int  \t %s = \t %d; // %s\n", NDDLUtil.escape(constant.getName()), val.getExactValue(), val.getUnit().toString());
			} else {
				out.printf("float  \t %s = \t %f; // %s\n", NDDLUtil.escape(constant.getName()), val.getEstimatedValue(), val.getUnit().toString());
			}
			return;
		} catch (Exception e) {
			out.printf("// **Unhandled amount**");
		}
	} else if (value instanceof Boolean) {
		out.printf("bool");
	} else if (value instanceof Float || value instanceof Double) {
		out.printf("float");
	} else if (value instanceof Integer || value instanceof Long) {
		out.printf("int");
	} else if (value instanceof String) {
		out.printf("string");
	} else {
		out.printf("// **Unknown type**");
	}
	out.printf(" \t %s = \t ", NDDLUtil.escape(constant.getName()));
	if (value instanceof String) {
		out.printf("\"%s\"", value); // String in quotes
	} else if (value instanceof Float || value instanceof Double) {
		out.printf("%f", value); // Nddl disallows exponents
	} else {
		out.print(value);
	}
	out.printf(";");
	if (constant.getUnits() != null)
		out.printf(" // %s", constant.getUnits());
	out.printf("\n");
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:49,代码来源:NumericResourceTranslator.java


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