11/*
2- * Copyright 2024 Todd Ginsberg
2+ * Copyright 2024-2026 Todd Ginsberg
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -60,8 +60,8 @@ static class State implements BigDecimalGatherer.State {
6060 final boolean includePartialValues ;
6161 final BigDecimal [] series ;
6262 BigDecimal sum = BigDecimal .ZERO ;
63- BigDecimal count = BigDecimal .ZERO ;
6463 BigDecimal average = BigDecimal .ZERO ;
64+ int count = 0 ;
6565 int index = 0 ;
6666
6767 private State (final int lookBack , final boolean includePartialValues ) {
@@ -72,18 +72,18 @@ private State(final int lookBack, final boolean includePartialValues) {
7272
7373 @ Override
7474 public boolean canCalculate () {
75- return includePartialValues || count . intValue () >= series .length ;
75+ return includePartialValues || count >= series .length ;
7676 }
7777
7878 @ Override
7979 public void add (final BigDecimal element , final MathContext mathContext ) {
8080 sum = sum .subtract (series [index ]).add (element , mathContext );
8181 series [index % series .length ] = element ;
8282 index = (index + 1 ) % series .length ;
83- if (count . intValue () < series .length ) {
84- count = count . add ( BigDecimal . ONE ) ;
83+ if (count < series .length ) {
84+ count ++ ;
8585 }
86- average = sum .divide (count , mathContext );
86+ average = sum .divide (BigDecimal . valueOf ( count ) , mathContext );
8787 }
8888
8989 @ Override
0 commit comments