65 * argument, and a given update as the other argument. For example,
66 * to maintain a running maximum value, you could supply {@code
67 * Long::max} along with {@code Long.MIN_VALUE} as the identity.
68 *
69 * <p>Class {@link LongAdder} provides analogs of the functionality of
70 * this class for the common special case of maintaining counts and
71 * sums. The call {@code new LongAdder()} is equivalent to {@code new
72 * LongAccumulator((x, y) -> x + y, 0L)}.
73 *
74 * <p>This class extends {@link Number}, but does <em>not</em> define
75 * methods such as {@code equals}, {@code hashCode} and {@code
76 * compareTo} because instances are expected to be mutated, and so are
77 * not useful as collection keys.
78 *
79 * @since 1.8
80 * @author Doug Lea
81 */
82 public class LongAccumulator extends Striped64 implements Serializable {
83 private static final long serialVersionUID = 7249069246863182397L;
84
85 private final LongBinaryOperator function;
86 private final long identity;
87
88 /**
89 * Creates a new instance using the given accumulator function
90 * and identity element.
91 * @param accumulatorFunction a side-effect-free function of two arguments
92 * @param identity identity (initial value) for the accumulator function
93 */
94 public LongAccumulator(LongBinaryOperator accumulatorFunction,
95 long identity) {
96 this.function = accumulatorFunction;
97 base = this.identity = identity;
98 }
99
100 /**
101 * Updates with the given value.
102 *
103 * @param x the value
104 */
222 }
223
224 /**
225 * Serialization proxy, used to avoid reference to the non-public
226 * Striped64 superclass in serialized forms.
227 * @serial include
228 */
229 private static class SerializationProxy implements Serializable {
230 private static final long serialVersionUID = 7249069246863182397L;
231
232 /**
233 * The current value returned by get().
234 * @serial
235 */
236 private final long value;
237
238 /**
239 * The function used for updates.
240 * @serial
241 */
242 private final LongBinaryOperator function;
243
244 /**
245 * The identity value.
246 * @serial
247 */
248 private final long identity;
249
250 SerializationProxy(long value,
251 LongBinaryOperator function,
252 long identity) {
253 this.value = value;
254 this.function = function;
255 this.identity = identity;
256 }
257
258 /**
259 * Returns a {@code LongAccumulator} object with initial state
260 * held by this proxy.
261 *
|
65 * argument, and a given update as the other argument. For example,
66 * to maintain a running maximum value, you could supply {@code
67 * Long::max} along with {@code Long.MIN_VALUE} as the identity.
68 *
69 * <p>Class {@link LongAdder} provides analogs of the functionality of
70 * this class for the common special case of maintaining counts and
71 * sums. The call {@code new LongAdder()} is equivalent to {@code new
72 * LongAccumulator((x, y) -> x + y, 0L)}.
73 *
74 * <p>This class extends {@link Number}, but does <em>not</em> define
75 * methods such as {@code equals}, {@code hashCode} and {@code
76 * compareTo} because instances are expected to be mutated, and so are
77 * not useful as collection keys.
78 *
79 * @since 1.8
80 * @author Doug Lea
81 */
82 public class LongAccumulator extends Striped64 implements Serializable {
83 private static final long serialVersionUID = 7249069246863182397L;
84
85 @SuppressWarnings("serial") // Not statically typed as Serializable
86 private final LongBinaryOperator function;
87 private final long identity;
88
89 /**
90 * Creates a new instance using the given accumulator function
91 * and identity element.
92 * @param accumulatorFunction a side-effect-free function of two arguments
93 * @param identity identity (initial value) for the accumulator function
94 */
95 public LongAccumulator(LongBinaryOperator accumulatorFunction,
96 long identity) {
97 this.function = accumulatorFunction;
98 base = this.identity = identity;
99 }
100
101 /**
102 * Updates with the given value.
103 *
104 * @param x the value
105 */
223 }
224
225 /**
226 * Serialization proxy, used to avoid reference to the non-public
227 * Striped64 superclass in serialized forms.
228 * @serial include
229 */
230 private static class SerializationProxy implements Serializable {
231 private static final long serialVersionUID = 7249069246863182397L;
232
233 /**
234 * The current value returned by get().
235 * @serial
236 */
237 private final long value;
238
239 /**
240 * The function used for updates.
241 * @serial
242 */
243 @SuppressWarnings("serial") // Not statically typed as Serializable
244 private final LongBinaryOperator function;
245
246 /**
247 * The identity value.
248 * @serial
249 */
250 private final long identity;
251
252 SerializationProxy(long value,
253 LongBinaryOperator function,
254 long identity) {
255 this.value = value;
256 this.function = function;
257 this.identity = identity;
258 }
259
260 /**
261 * Returns a {@code LongAccumulator} object with initial state
262 * held by this proxy.
263 *
|