equal
deleted
inserted
replaced
63 * of magnitude. |
63 * of magnitude. |
64 * |
64 * |
65 * <p>Class {@link DoubleAdder} provides analogs of the functionality |
65 * <p>Class {@link DoubleAdder} provides analogs of the functionality |
66 * of this class for the common special case of maintaining sums. The |
66 * of this class for the common special case of maintaining sums. The |
67 * call {@code new DoubleAdder()} is equivalent to {@code new |
67 * call {@code new DoubleAdder()} is equivalent to {@code new |
68 * DoubleAccumulator((x, y) -> x + y, 0.0}. |
68 * DoubleAccumulator((x, y) -> x + y, 0.0)}. |
69 * |
69 * |
70 * <p>This class extends {@link Number}, but does <em>not</em> define |
70 * <p>This class extends {@link Number}, but does <em>not</em> define |
71 * methods such as {@code equals}, {@code hashCode} and {@code |
71 * methods such as {@code equals}, {@code hashCode} and {@code |
72 * compareTo} because instances are expected to be mutated, and so are |
72 * compareTo} because instances are expected to be mutated, and so are |
73 * not useful as collection keys. |
73 * not useful as collection keys. |
82 private final long identity; // use long representation |
82 private final long identity; // use long representation |
83 |
83 |
84 /** |
84 /** |
85 * Creates a new instance using the given accumulator function |
85 * Creates a new instance using the given accumulator function |
86 * and identity element. |
86 * and identity element. |
|
87 * @param accumulatorFunction a side-effect-free function of two arguments |
|
88 * @param identity identity (initial value) for the accumulator function |
87 */ |
89 */ |
88 public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction, |
90 public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction, |
89 double identity) { |
91 double identity) { |
90 this.function = accumulatorFunction; |
92 this.function = accumulatorFunction; |
91 base = this.identity = Double.doubleToRawLongBits(identity); |
93 base = this.identity = Double.doubleToRawLongBits(identity); |
92 } |
94 } |
93 |
95 |
94 /** |
96 /** |
95 * Updates with the given value. |
97 * Updates with the given value. |
96 * |
98 * |