本文整理汇总了Java中org.jscience.physics.amount.Amount.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java Amount.valueOf方法的具体用法?Java Amount.valueOf怎么用?Java Amount.valueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jscience.physics.amount.Amount
的用法示例。
在下文中一共展示了Amount.valueOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@Override
public Double convert(Double value, MassUnit from, MassUnit to) {
if (value == null)
return null;
if (from.equals(UNSUPPORTED) || to.equals(UNSUPPORTED))
return null;
Unit fUnit = get(from);
Unit tUnit = get(to);
if (fUnit == null || tUnit == null)
return null;
Amount<Mass> m = Amount.valueOf(value, fUnit);
return m.doubleValue(tUnit);
}
示例2: convert
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@Override
public Double convert(Double value, DataAmountUnit from, DataAmountUnit to) {
if (value == null)
return null;
if (from.equals(UNSUPPORTED) || to.equals(UNSUPPORTED))
return null;
Unit fUnit = get(from);
Unit tUnit = get(to);
if (fUnit == null || tUnit == null)
return null;
Amount<DataAmount> m = Amount.valueOf(value, fUnit);
return m.doubleValue(tUnit);
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:18,代码来源:DefaultDataAmountConverter.java
示例3: convert
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@Override
public Double convert(Double value, LengthUnit from, LengthUnit to) {
if (value == null)
return null;
if (from.equals(UNSUPPORTED) || to.equals(UNSUPPORTED))
return null;
Unit fUnit = get(from);
Unit tUnit = get(to);
if (fUnit == null || tUnit == null)
return null;
Amount<Length> m = Amount.valueOf(value, fUnit);
return m.doubleValue(tUnit);
}
示例4: testDelayedNumericProfileEffect
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
public void testDelayedNumericProfileEffect() throws Exception {
Amount<Duration> startOffset = Amount.valueOf(30, NonSI.MINUTE);
final ProfileMember profileMember = activity.getMember(ProfileMember.class);
assertNotNull(profileMember);
assertNotNull(ResourceUtils.getProfile(plan, KEY_TEST_PROFILE));
final ProfileEffect effect = createProfileEffect(startOffset, "10", DateUtils.ZERO_DURATION, "-10");
TransactionUtils.writing(plan, new Runnable() {
@Override
public void run() {
profileMember.getEffects().add(effect);
}
});
recomputePlan(plan);
assertProfileValue(plan, KEY_TEST_PROFILE, ACTIVITY_START, null);
assertProfileValue(plan, KEY_TEST_PROFILE, DateUtils.add(ACTIVITY_START, startOffset), Amount.valueOf(10, Unit.ONE));
assertProfileValue(plan, KEY_TEST_PROFILE, ACTIVITY_END , Amount.valueOf( 0, Unit.ONE));
}
示例5: getStandardDeviation
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
/** @return the standard deviation from the mean of the non-interpolated points in the profile */
public static <T extends Quantity> Amount<T> getStandardDeviation(Profile<Amount<T>> profile) {
Amount<T> meanAmount = getMean(profile);
if (meanAmount==null) return null;
double mean = meanAmount.getEstimatedValue();
double weightedVariance = 0;
long totalTime = 0;
List<DataPoint<Amount<T>>> dataPoints = profile.getDataPoints();
Date startOfInterval = null;
for (DataPoint<Amount<T>> datapoint : dataPoints) {
Date endOfInterval = datapoint.getDate();
if (startOfInterval != null) {
long lengthOfInterval = endOfInterval.getTime() - startOfInterval.getTime();
Date midpointOfInterval = DateUtils.add(startOfInterval, Amount.valueOf(lengthOfInterval/2, SI.MILLI(SI.SECOND)));
Number meanValueForInterval = profile.getDataPoint(midpointOfInterval).getNumericValue();
if (meanValueForInterval != null) {
double differenceFromMean = mean-meanValueForInterval.doubleValue();
weightedVariance += (differenceFromMean * differenceFromMean) * lengthOfInterval;
totalTime += lengthOfInterval;
}
}
startOfInterval = endOfInterval;
}
if (totalTime==0) return null;
return (Amount<T>) Amount.valueOf(Math.sqrt(weightedVariance/totalTime), 0, profile.getUnits());
}
示例6: coalesceElements
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@Override
protected Object coalesceElements(Collection elements) {
Date earliest = null;
Date latest = null;
for (Object o : elements) {
IObservableValue v = (IObservableValue) o;
Date value = (Date) v.getValue();
if (value == null) {
continue;
}
if (earliest == null || value.before(earliest)) {
earliest = value;
}
if (latest == null || value.after(latest)) {
latest = value;
}
}
if (latest == null || earliest == null) {
return Amount.valueOf(0L, SI.MILLI(SI.SECOND));
}
return Amount.valueOf(latest.getTime() - earliest.getTime(), SI.MILLI(SI.SECOND));
}
示例7: updateOffset
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Amount<Duration> updateOffset() {
String string = text.getText();
if (string != null && string.length() > 0) {
try {
if (string.startsWith("+") || string.startsWith("-")) {
String durationString = string.substring(1);
Amount<Duration> duration = DURATION_STRINGIFIER.getJavaObject(durationString, null);
if ((duration != null) && string.startsWith("-")) {
duration = duration.opposite();
}
return duration;
} else {
Date date = DATE_STRINGIFIER.getJavaObject(string, referenceDate);
long delta = date.getTime() - referenceDate.getTime();
return Amount.valueOf(delta, SI.MILLI(SI.SECOND));
}
} catch (Exception e) {
// fall through to set false
}
}
return null;
}
示例8: parseLimitText
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
private Amount parseLimitText(String text) throws ParseException {
Plot plot = (Plot) getManagedForm().getInput();
try {
return EnsembleAmountFormat.INSTANCE.parseAmount(text, plot.getProfile().getUnits());
} catch (Exception e) {
try {
double d = Double.parseDouble(text);
Unit<?> u = plot.getProfile().getUnits();
return Amount.valueOf(d, u);
} catch (Exception x) {
Amount durationValue = (Amount) JScienceFactory.eINSTANCE.createFromString(JSciencePackage.Literals.EDURATION, text);
if (durationValue != null) {
return durationValue;
}
}
}
Unit<?> units = plot.getProfile().getUnits();
if (units == null) {
units = Unit.ONE;
}
throw new ParseException("Cannot parse '" + text + "', try 1.0 " + EnsembleUnitFormat.INSTANCE.format(units), 0);
}
示例9: main
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, ClassNotFoundException {
A a = new A(2L, Amount.valueOf(3.0, Currency.EUR));
File outputFile = File.createTempFile("prefix", "suffix");
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream)) {
objectOutputStream.writeObject(a);
objectOutputStream.flush();
}
FileInputStream fileInputStream = new FileInputStream(outputFile);
A aReloaded;
try (ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) {
aReloaded = (A) objectInputStream.readObject();
}
System.out.println(aReloaded.toString());
}
示例10: test
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@Test
public void test() {
Amount<ElectricCurrent> current1 = Amount.valueOf(12, AMPERE);
Amount<ElectricCurrent> current2 = Amount.valueOf(2, AMPERE);
@SuppressWarnings("unchecked")
Amount<Dimensionless> result = (Amount<Dimensionless>) current1.divide(current2);
assertNotNull(result);
System.out.println(result.getUnit());
System.out.println(result.doubleValue(ONE));
}
示例11: testMisc
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
@Test(expected = ConversionException.class)
public void testMisc() {
Amount<Length> position = Amount.valueOf(1, 0.02, SI.METER);
Amount<Length> position2 = Amount.valueOf(1, 0.02, SI.METER);
Amount<?> positionResult = position.times(position2);
System.out.println(positionResult);
System.out.println(positionResult.getAbsoluteError());
System.out.println(positionResult.getRelativeError());
position.divide(position2).to(SI.METER);
}
示例12: getInitialValue
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
private Amount getInitialValue(T resourceDef, Unit<?> units) {
Amount initialValue = null;
try {
String defaultValueLiteral = resourceDef.getDefaultValueLiteral();
if (!CommonUtils.isNullOrEmpty(defaultValueLiteral)) {
initialValue = AmountUtils.valueOf(defaultValueLiteral, units);
}
} catch (Exception e) {
// we tried
}
if (initialValue == null) {
initialValue = Amount.valueOf(0L, units);
}
return initialValue;
}
示例13: createEActivity
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
private EActivity createEActivity(EActivityDef def, EPlanElement eParent, boolean isSubActivity) {
if (def == null) {
return null;
}
EActivity activity = gov.nasa.ensemble.core.model.plan.PlanFactory.eINSTANCE.createEActivity();
activity.setName(def.getName());
activity.setIsSubActivity(isSubActivity || (eParent instanceof EActivity));
activity.setData(ADParameterMemberFactory.FACTORY.createData(def));
TemporalMember temporalMember = activity.getMember(TemporalMember.class);
temporalMember.setStartTime(null);
String duration = def.getDuration();
if (duration == null) {
duration = DEFAULT_DURATION;
}
if (duration != null) {
// SPF-6383
try {
long time = DurationFormat.parseFormattedDuration(duration);
Amount<Duration> amount = Amount.valueOf(time, DURATION_UNITS);
temporalMember.setDuration(amount);
} catch (Exception e) {
// ignore these
}
}
setDefaultMemberValues(activity, def);
return activity;
}
示例14: addNetworkDurationConstraint
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
private TemporalNetwork<Time>.TemporalConstraint addNetworkDurationConstraint(Amount<Duration> duration, TemporalNetwork<Time>.Timepoint start, TemporalNetwork<Time>.Timepoint end) {
TemporalNetwork<Time>.TemporalConstraint durationConstraint = null;
if (duration != null) {
if (!duration.isGreaterThan(Amount.valueOf(0, SI.SECOND))) {
duration = Amount.valueOf(1, SI.MILLI(SI.SECOND));
}
Time timeDuration = model.convertTimeDistanceToNetwork(duration);
durationConstraint = network.addTemporalConstraint(start, end, timeDuration, timeDuration);
} else {
durationConstraint = network.addTemporalConstraint(start, end, network.getTime(0L), network.getTime(DistanceGraph.POS_INFINITY)); // allow any nonnegative duration for activities with no
// extent
}
return durationConstraint;
}
示例15: computeDelta
import org.jscience.physics.amount.Amount; //导入方法依赖的package包/类
private Amount<Duration> computeDelta(ConstraintPoint pointA, ConstraintPoint pointB) {
Date timeA = pointA.getDate();
Date timeB = pointB.getDate();
if ((timeA == null) || (timeB == null)) {
return Amount.valueOf(-1, SI.SECOND); // error condition
}
Amount<Duration> delta = DateUtils.subtract(timeA, timeB).abs();
return delta;
}