/** * The value of this beed is recalculated. This is done by iterating over the arguments. When * there are no terms, the result is equal to {@link #initialValue()}. When one of the terms is * null, the result is null. When all terms are effective, the result is dependent on the specific * subclass. */ private final void recalculate() { $value = initialValue(); for (RealBeed<?> argument : $arguments) { if (!argument.isEffective()) { assignEffective(false); return; } $value = operation($value, argument.getdouble()); } assignEffective(true); }
/** * @pre argument != null; * @post new.getNbOccurrences(argument) == getNbOccurrences(argument) + 1; */ public final void addArgument(RealBeed<?> argument) { assert argument != null; addUpdateSource(argument); $arguments.add(argument); // recalculate(); optimization if ($effective) { double oldValue = $value; if (!argument.isEffective()) { assignEffective(false); } else { assert argument.isEffective(); if (argument.getdouble() != initialValue()) { $value = operation($value, argument.getdouble()); } } if ((!$effective) || !MathUtil.equalPrimitiveValue(oldValue, $value)) { updateDependents(new ActualDoubleEvent(this, oldValue, $effective ? $value : null, null)); } } // otherwise, there is an existing null argument; the new argument cannot change null value }
public final void toStringDepth(StringBuffer sb, int depth, NumberFormat numberFormat) { Iterator<RealBeed<?>> i = $arguments.iterator(); while (i.hasNext()) { RealBeed<?> argument = i.next(); sb.append("("); if (depth == 1) { sb.append(numberFormat.format(argument.getdouble())); } else { argument.toStringDepth(sb, depth - 1, numberFormat); } sb.append(")" + getNbOccurrencesOperatorString() + getNbOccurrences(argument)); if (i.hasNext()) { sb.append(getOperatorString()); } } }