278 |
|
} |
279 |
|
|
280 |
|
/** |
281 |
+ |
* Equivalent to {@code add(1)}. |
282 |
+ |
*/ |
283 |
+ |
public void increment() { |
284 |
+ |
add(1L); |
285 |
+ |
} |
286 |
+ |
|
287 |
+ |
/** |
288 |
+ |
* Equivalent to {@code add(-1)}. |
289 |
+ |
*/ |
290 |
+ |
public void decrement() { |
291 |
+ |
add(-1L); |
292 |
+ |
} |
293 |
+ |
|
294 |
+ |
/** |
295 |
|
* Returns an estimate of the current sum. The result is |
296 |
|
* calculated by summing multiple variables, so may not be |
297 |
|
* accurate if updates occur concurrently with this method. |
313 |
|
} |
314 |
|
|
315 |
|
/** |
316 |
< |
* Resets each of the variables to zero. This is effective in |
317 |
< |
* fully resetting the sum only if there are no concurrent |
318 |
< |
* updates. |
305 |
< |
*/ |
306 |
< |
public void reset() { |
307 |
< |
Adder[] as = adders; |
308 |
< |
if (as != null) { |
309 |
< |
int n = as.length; |
310 |
< |
for (int i = 0; i < n; ++i) { |
311 |
< |
Adder a = as[i]; |
312 |
< |
if (a != null) |
313 |
< |
a.value = 0L; |
314 |
< |
} |
315 |
< |
} |
316 |
< |
} |
317 |
< |
|
318 |
< |
/** |
319 |
< |
* Equivalent to {@code add(1)}. |
320 |
< |
*/ |
321 |
< |
public void increment() { |
322 |
< |
add(1L); |
323 |
< |
} |
324 |
< |
|
325 |
< |
/** |
326 |
< |
* Equivalent to {@code add(-1)}. |
327 |
< |
*/ |
328 |
< |
public void decrement() { |
329 |
< |
add(-1L); |
330 |
< |
} |
331 |
< |
|
332 |
< |
/** |
333 |
< |
* Equivalent to {@link #sum} followed by {@link #reset}. |
316 |
> |
* Resets each of the variables to zero, returning the estimated |
317 |
> |
* previous sum. This is effective in fully resetting the sum only |
318 |
> |
* if there are no concurrent updates. |
319 |
|
* |
320 |
< |
* @return the estimated sum |
320 |
> |
* @return the estimated previous sum |
321 |
|
*/ |
322 |
< |
public long sumAndReset() { |
322 |
> |
public long reset() { |
323 |
|
long sum = 0L; |
324 |
|
Adder[] as = adders; |
325 |
|
if (as != null) { |