refactor(documents): YearMonth.from(d).toString() for density key (#385)
YearMonth.from(d).toString() emits the same canonical YYYY-MM string
as the previous String.format("%04d-%02d", …) call but reads as a
single intent-revealing expression. Existing assertions on
"1915-08", "1916-01", … pin the output format unchanged.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,7 @@ import java.io.IOException;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.YearMonth;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -171,8 +172,7 @@ public class DocumentService {
|
|||||||
|
|
||||||
Map<String, Integer> counts = new java.util.TreeMap<>();
|
Map<String, Integer> counts = new java.util.TreeMap<>();
|
||||||
for (LocalDate d : dates) {
|
for (LocalDate d : dates) {
|
||||||
String month = String.format("%04d-%02d", d.getYear(), d.getMonthValue());
|
counts.merge(YearMonth.from(d).toString(), 1, Integer::sum);
|
||||||
counts.merge(month, 1, Integer::sum);
|
|
||||||
}
|
}
|
||||||
List<MonthBucket> buckets = counts.entrySet().stream()
|
List<MonthBucket> buckets = counts.entrySet().stream()
|
||||||
.map(e -> new MonthBucket(e.getKey(), e.getValue()))
|
.map(e -> new MonthBucket(e.getKey(), e.getValue()))
|
||||||
|
|||||||
Reference in New Issue
Block a user