Repository navigation
Fix 20 verified bugs, name magic numbers, clarify names and comments - #15
Conversation
- add(0, e) on a non-empty list now inserts at the start instead of throwing IllegalArgumentException - removeFromEnd() on an empty list throws IllegalStateException, like removeFromStart(), instead of NullPointerException - remove(position) rejects an unoccupied position with IllegalArgumentException instead of NullPointerException - removeFromStart() clears the new first node's previous link Each case has a test that failed before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- add(position, e) accepts position == size(), so it can append and insert into an empty vector - remove(position) rejects an unoccupied position with IllegalArgumentException; before, a position past the end silently removed the last element and an empty vector's size dropped to -1 Each case has a test that failed before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Element.equals returns false for objects of other types instead of throwing ClassCastException - Element.hashCode is now overridden from the name, so equal elements are found in hash-based collections - Set.add/remove reject an empty word with IllegalArgumentException instead of StringIndexOutOfBoundsException Each case has a test that failed before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- toArray casts after taking % 10, so numbers beyond the int range give the right digits (12345678901 was [-7, 0, 9, ...]) - toArray of a negative number gives the digits of its absolute value ([2, 1] for -12, was [-2, -1, 0]) - containsDigit(0, 0) is true - length(negative) counts the digits of the absolute value (was 1) Each case has a test that failed before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Anagram (B18, B19, B22-B24) - Statistics.median and meanAbsoluteDeviation reject empty data with IllegalArgumentException (was ArrayIndexOutOfBoundsException / NaN) - NumberTheory.lcm returns 0 when either number is 0 (was division by zero) and throws ArithmeticException on overflow via Math.multiplyExact (lcm(4000000007, 4000000009) was negative) - StringUtils.isAnagram lower-cases with Locale.ROOT, so "TITLE" and "title" are anagrams under a Turkish default locale too Each case has a test that failed before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- B26: fibonacciSimpleBinetFormula is exact (rounded) up to n = 70, not 67; Javadoc and the exhaustive property range now say 70 - B28: BinarySearch.find uses O(log n) stack space, not O(1) - M6: explain the 6k +/- 1 step in isPrime - N18: TriangleType display names in English: Equilateral, Scalene, Isosceles (was Equilatero, Escaleno, Isoceles) - O1/O2: LinkedList exception messages in English, with the position - O3: Sequences.fibonacci message is "n must be non-negative: <n>" - O7: drop commented-out code in Geometry.distance - O8: replace the formatter-split trailing comments in containsDigit - O9: drop comments that restate the code - O10: "gdc" typo; O11: name the Fisher-Yates shuffle Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- M1: Set.BUCKET_COUNT (26) - M2: Vector.INITIAL_CAPACITY (100) - M3/M4: Measurement.KILOMETERS_PER_MILE and MILES_PER_KILOMETER - M5: Sequences.SQRT_5 and GOLDEN_RATIO instead of recomputing sqrt(5) four times; the exhaustive Fibonacci properties confirm identical results - M7: BigInteger.ZERO/ONE/TWO and BigInteger.valueOf instead of parsing strings - M8: Reader.BUFFER_SIZE is static Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-N25, N27) Only non-API names: private members, parameters and locals, e.g. theArray -> values, arrA -> sortedA, bNumber -> divisor, minorsFound -> boundary, analysis -> position, guaranteesSpace -> ensureCapacity, Reader's din/buf/cnt/c/ret/neg -> input/line/length/ nextByte/result/negative. Verified: compiled without debug info, the bytecode is identical to before except for the six renamed private members (RANDOM, randomBetweenInclusive, sortedLowerCaseChars, ensureCapacity, findSmallestIndex, input). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 21 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #15 +/- ##
============================================
+ Coverage 99.65% 99.83% +0.17%
- Complexity 279 296 +17
============================================
Files 24 24
Lines 576 594 +18
Branches 94 102 +8
============================================
+ Hits 574 593 +19
+ Partials 2 1 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
One correctness issue should be fixed before merging: Numbers.containsDigit does not preserve its sign-insensitive behavior for Long.MIN_VALUE because negation overflows. The required regression scenarios are otherwise covered, and no additional acceptance-criteria gaps were identified.
Test suggestions
- Insert at position zero in a non-empty LinkedList and preserve previous links
- Reject removing from the end of an empty LinkedList
- Reject removal at an unoccupied LinkedList position without changing size
- Clear the new first node's previous link after LinkedList removal
- Insert into a Vector at size and into an empty Vector
- Reject invalid Vector removals, including negative, oversized, and empty-vector positions
- Compare Element with another type and use equal elements in hash-based collections
- Reject empty words in Set add and remove
- Convert values beyond int range and negative values to reversed digit arrays
- Handle zero in containsDigit and negative values in length
- Reject empty arrays for median and mean absolute deviation
- Return zero for LCM with zero operands and throw on overflow
- Perform locale-independent anagram comparison
- Verify rounded simple Binet results through index 70
- Verify English TriangleType display names and updated exception messages
Make this review better
TIP Add a ticket key to the branch or title so the reviewer can check the PR against it. Or tell us which ticket tracker you use here.
TIP Add Codacy review.md instructions or an AGENTS.md so the reviewer knows your conventions.
TIP How was this review? Give us feedback
| public static boolean containsDigit(final long number, final long digit) { | ||
| long thisNumber = number >= 0 ? number : -number; | ||
| long thisDigit; | ||
| long remaining = number >= 0 ? number : -number; |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Handle Long.MIN_VALUE without negating it, such as by using overflow-safe digit extraction or a string representation, and add a regression test for this boundary value.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Covers the '\r' branch of the line-ending check, which no test reached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clean-code PR D of 4: the rows approved from the findings review. STRUCTURAL rows, public-API renames, behaviour changes (B5, B10, B20, B25) and B27 are not included.
Bug fixes (each with a test that failed first)
1bdcee5LinkedList:add(0, e)on a non-empty list;removeFromEnd()on empty →IllegalStateException;remove(size())→IllegalArgumentException;removeFromStart()clears the stalepreviousf0deabfVector:add(size(), e)appends and works on an empty vector;removevalidates its position (it used to remove the wrong element, or leave size −1)92b440aElement.equalsis type-safe andhashCodeis overridden;Setrejects an empty word03b59b6Numbers.toArrayis correct beyond the int range and for negatives;containsDigit(0, 0)is true;length(negative)counts digitsd59eba5Statisticsrejects empty data;lcmwith 0 returns 0, and overflow now throws instead of returning a negative number;isAnagramlower-cases withLocale.ROOTComments and messages:
e6fcd6aB26 (Binet exact up to 70, not 67), B28 (
BinarySearchuses O(log n) stack space), M6 (6k ± 1 explained), N18 (TriangleTypedisplay names in English), O1–O3 (English exception messages), O7–O11 (dead code, broken and redundant comments,gdctypo, Fisher–Yates).Named constants:
3f5c252BUCKET_COUNT,INITIAL_CAPACITY,KILOMETERS_PER_MILE/MILES_PER_KILOMETER,SQRT_5/GOLDEN_RATIO,BigInteger.ZERO/ONE/TWOandvalueOf, and astaticBUFFER_SIZE.Renames:
88c7139Non-API names only: private members, parameters and locals (N1–N11, N14, N20–N25, N27). Verified: compiled without debug info, the bytecode is identical to before, except for the six renamed private members.
Visible behaviour changes callers may notice
TriangleType.getName()now returns English names.LinkedListandSequencesexception messages changed.Statistics.median/meanAbsoluteDeviationon an empty array now throwIllegalArgumentException.lcmnow throws on overflow.Test plan
./mvnw clean verify: 610 tests; doclint, Spotless, PMD and coverage floors all pass🤖 Generated with Claude Code