Fixar #140: Implementerade StringUtil.reverse(String) metod#141
Fixar #140: Implementerade StringUtil.reverse(String) metod#141
Conversation
WalkthroughAdds new breeze.util.MathUtil with a static reverse(String) method. Removes numerous public APIs across ascii formatting, circular buffer, collections, control utilities (tuples, lazy), CSV, multimap, functional control (Either/Try/RetryExecutor), graph, math, matrix, SIMD, SQL builder, string interpolation, util helpers, and vector packages. Changes
Sequence Diagram(s)Estimated code review effort🎯 4 (Complex) | ⏱️ ~55 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/java/StringUtil.java (1)
3-8: Consider adding JavaDoc for the public API.While not critical, documenting the public API improves usability and clarifies behavior (especially the null-handling contract).
+ /** + * Reverses the given string. + * + * @param input the string to reverse, may be null + * @return the reversed string, or null if input is null + */ public static String reverse(String input) {
| @@ -0,0 +1,9 @@ | |||
| public class StringUtil { | |||
There was a problem hiding this comment.
Add a package declaration.
The class is in the default package, which is strongly discouraged for production code. It prevents imports from other packages, risks namespace conflicts, and complicates future refactoring.
Add a package declaration at the top of the file. For example:
+package com.fungover.breeze.util;
+
public class StringUtil {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public class StringUtil { | |
| package com.fungover.breeze.util; | |
| public class StringUtil { |
🤖 Prompt for AI Agents
In src/main/java/StringUtil.java at line 1, the class is in the default package;
add a package declaration (e.g. package com.yourorg.util;) as the first
non-comment line, then move the file into the corresponding directory
src/main/java/com/yourorg/util/ so the package path matches the filesystem;
update any imports/usages elsewhere to import com.yourorg.util.StringUtil and
run a quick build to ensure package references are correct.
| public static String reverse(String input) { | ||
| if (input == null) { | ||
| return null; | ||
| } | ||
| return new StringBuilder(input).reverse().toString(); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
Implementation looks good. Verify test coverage.
The implementation is correct and idiomatic—using StringBuilder.reverse() is the standard approach. The null handling is reasonable.
However, no unit tests are included in this PR. Ensure tests exist to verify:
- Normal cases (e.g.,
reverse("abc")→"cba") - Edge cases (empty string, single character)
- Null input handling
Run the following script to check for existing tests:
🏁 Script executed:
#!/bin/bash
# Description: Search for test files that might test StringUtil.reverse
# Look for test files that reference StringUtil or reverse
rg -t java --type-add 'test:*Test.java' -g '*Test.java' -C 3 'StringUtil|reverse'Length of output: 3171
🏁 Script executed:
#!/bin/bash
# Search for class Strings to verify target of tests
rg -n "class Strings" -g "*.java"Length of output: 155
Update tests to cover StringUtil.reverse
Tests currently invoke Strings.reverse(…) (in Strings.java), not StringUtil.reverse(…). Add or update unit tests for StringUtil.reverse to verify:
- Normal strings (e.g.
"abc"→"cba") - Empty and single‐char inputs
nullhandling
[src/main/java/StringUtil.java]
🤖 Prompt for AI Agents
In src/main/java/StringUtil.java around lines 3 to 8, the test suite is
exercising Strings.reverse(...) instead of StringUtil.reverse(...); update or
add unit tests to call StringUtil.reverse and assert expected behavior for
normal strings (e.g. "abc" -> "cba"), empty string ("" -> ""), single-character
inputs (e.g. "x" -> "x"), and null input (null -> null); ensure tests import/
reference the correct class (StringUtil) and include assertions for each case,
using the project's test framework and placing the new/updated tests in the
appropriate test package so they run with the existing test runner.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/fungover/breeze/util/StringUtil.java (1)
5-10: LGTM! Thereversemethod correctly implements the requirement.The implementation is clean and efficient, using
StringBuilder.reverse()to reverse the input string. The null handling is appropriate.Consider adding unit tests to verify the behavior for various inputs (null, empty string, single character, multiple characters). Do you want me to generate test cases or open an issue to track this?
| public static double calculateArea(double length, double width) { | ||
| if (length <= 0 || width <= 0) { | ||
| return 0; | ||
| } | ||
| return length * width; | ||
| } |
There was a problem hiding this comment.
Remove the calculateArea method—it's out of scope for this PR.
The calculateArea method is not mentioned in issue #140 or the PR description. This PR should only implement StringUtil.reverse(String) as specified in the linked issue. Including unrelated functionality introduces scope creep and makes the PR harder to review.
Please remove this method or create a separate PR/issue for it.
🤖 Prompt for AI Agents
In src/main/java/com/fungover/breeze/util/StringUtil.java around lines 12 to 17,
remove the calculateArea(double length, double width) method because it is out
of scope for this PR; either delete these lines entirely from this commit or
move the logic into a new branch/PR tied to its own issue and revert any
references or tests added for it in this PR so this change only implements
StringUtil.reverse(String) as specified.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/java/com/fungover/breeze/util/MathUtil.java (1)
12-13: Consider throwing an exception for invalid input.Returning
0for non-positive dimensions silently hides invalid input, which could mask bugs in calling code. For a utility method, throwingIllegalArgumentExceptionwould make errors more explicit and easier to debug.public static double calculateArea(double length, double width) { if (length <= 0 || width <= 0) { - return 0; + throw new IllegalArgumentException("Length and width must be positive values"); } return length * width; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/fungover/breeze/util/MathUtil.java(1 hunks)
🔇 Additional comments (1)
src/main/java/com/fungover/breeze/util/MathUtil.java (1)
5-10: Javadoc language inconsistency.The Javadoc is written in Swedish while the code (class, method, and parameter names) is in English. This mixing may cause confusion for international contributors.
Please verify whether the project's coding guidelines specify a preferred language for documentation. If English is preferred, consider translating the Javadoc:
- /** - * Beräknar arean för en rektangel. - * @param length Rektangelns längd. - * @param width Rektangelns bredd. - * @return Arean, eller 0 om längd/bredd är noll eller negativ. - */ + /** + * Calculates the area of a rectangle. + * @param length The length of the rectangle. + * @param width The width of the rectangle. + * @return The area, or 0 if length/width is zero or negative. + */
| package com.fungover.breeze.util; | ||
|
|
||
| public class MathUtil { | ||
|
|
||
| /** | ||
| * Beräknar arean för en rektangel. | ||
| * @param length Rektangelns längd. | ||
| * @param width Rektangelns bredd. | ||
| * @return Arean, eller 0 om längd/bredd är noll eller negativ. | ||
| */ | ||
| public static double calculateArea(double length, double width) { | ||
| if (length <= 0 || width <= 0) { | ||
| return 0; | ||
| } | ||
| return length * width; | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
This entire class is out of scope for PR #141.
Issue #140 requests implementing StringUtil.reverse(String) to reverse strings. This MathUtil class with calculateArea is completely unrelated to that objective. Introducing unrelated functionality creates scope creep, makes the PR harder to review, and complicates git history.
Please remove this file from the PR and create a separate PR if area calculation functionality is needed.
🤖 Prompt for AI Agents
In src/main/java/com/fungover/breeze/util/MathUtil.java lines 1-17: this file is
unrelated to PR #141 and must be removed from the branch; remove the file from
the current PR (e.g., git rm
src/main/java/com/fungover/breeze/util/MathUtil.java && git commit -m "remove
unrelated MathUtil from PR #141" && git push) or, if you need to preserve the
changes, move them to a new feature branch (git checkout -b feature/math-util &&
git add src/main/java/com/fungover/breeze/util/MathUtil.java && git commit) and
open a separate PR for that work; then restore the original PR branch without
this file so PR #141 only contains the StringUtil.reverse implementation.
| public static double calculateArea(double length, double width) { | ||
| if (length <= 0 || width <= 0) { | ||
| return 0; | ||
| } | ||
| return length * width; | ||
| } |
There was a problem hiding this comment.
Duplicate calculateArea method across utility classes.
According to the AI summary, calculateArea(double, double) appears in both MathUtil and StringUtil. This violates the DRY principle and creates maintenance issues.
If area calculation is needed, it should exist only in MathUtil (the more appropriate location). Remove the duplicate from StringUtil.
🤖 Prompt for AI Agents
In src/main/java/com/fungover/breeze/util/MathUtil.java around lines 11 to 16,
the calculateArea(double, double) implementation is correct but duplicated in
StringUtil; remove the duplicate method from
src/main/java/com/fungover/breeze/util/StringUtil.java and update any callers to
reference MathUtil.calculateArea(...) instead of StringUtil; ensure StringUtil
no longer contains area logic, run a quick build/search to confirm no remaining
duplicates, and adjust imports in files that used the removed method.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (50)
src/main/java/breeze/util/MathUtil.java(1 hunks)src/main/java/org/fungover/breeze/ascii/AsciiTableFormatter.java(0 hunks)src/main/java/org/fungover/breeze/circularbuffer/CircularBuffer.java(0 hunks)src/main/java/org/fungover/breeze/circularbuffer/OverflowStrategy.java(0 hunks)src/main/java/org/fungover/breeze/collection/FList.java(0 hunks)src/main/java/org/fungover/breeze/collection/FPriorityQueue.java(0 hunks)src/main/java/org/fungover/breeze/collection/FQueue.java(0 hunks)src/main/java/org/fungover/breeze/collection/FSet.java(0 hunks)src/main/java/org/fungover/breeze/collection/FTree.java(0 hunks)src/main/java/org/fungover/breeze/collection/Node.java(0 hunks)src/main/java/org/fungover/breeze/collection/RedBlackTree.java(0 hunks)src/main/java/org/fungover/breeze/control/Lazy.java(0 hunks)src/main/java/org/fungover/breeze/control/Tuple2.java(0 hunks)src/main/java/org/fungover/breeze/control/Tuple3.java(0 hunks)src/main/java/org/fungover/breeze/control/Tuple4.java(0 hunks)src/main/java/org/fungover/breeze/csv/CsvReader.java(0 hunks)src/main/java/org/fungover/breeze/fmultimap/FMultiMap.java(0 hunks)src/main/java/org/fungover/breeze/funclib/control/Either.java(0 hunks)src/main/java/org/fungover/breeze/funclib/control/RetryExecutor.java(0 hunks)src/main/java/org/fungover/breeze/funclib/control/Try.java(0 hunks)src/main/java/org/fungover/breeze/funclib/control/package-info.java(0 hunks)src/main/java/org/fungover/breeze/graph/Dijkstra.java(0 hunks)src/main/java/org/fungover/breeze/graph/Edge.java(0 hunks)src/main/java/org/fungover/breeze/graph/Graph.java(0 hunks)src/main/java/org/fungover/breeze/graph/Node.java(0 hunks)src/main/java/org/fungover/breeze/graph/WeightedGraph.java(0 hunks)src/main/java/org/fungover/breeze/math/MathUtils.java(0 hunks)src/main/java/org/fungover/breeze/math/Quaternion.java(0 hunks)src/main/java/org/fungover/breeze/math/Ray.java(0 hunks)src/main/java/org/fungover/breeze/math/RayMath.java(0 hunks)src/main/java/org/fungover/breeze/math/Vector3.java(0 hunks)src/main/java/org/fungover/breeze/matrix/Matrix3x3.java(0 hunks)src/main/java/org/fungover/breeze/matrix/Matrix4x4.java(0 hunks)src/main/java/org/fungover/breeze/matrix/MatrixOps.java(0 hunks)src/main/java/org/fungover/breeze/simd/SimdArrayOps.java(0 hunks)src/main/java/org/fungover/breeze/simd/SimdArrayOpsParallel.java(0 hunks)src/main/java/org/fungover/breeze/simd/SimdUtils.java(0 hunks)src/main/java/org/fungover/breeze/simd/benchmarks/SimdBenchmarkUtils.java(0 hunks)src/main/java/org/fungover/breeze/sql/SQL.java(0 hunks)src/main/java/org/fungover/breeze/stringInterpolation/StringTemplate.java(0 hunks)src/main/java/org/fungover/breeze/util/Arrays.java(0 hunks)src/main/java/org/fungover/breeze/util/FDeque.java(0 hunks)src/main/java/org/fungover/breeze/util/PasswordGenerator.java(0 hunks)src/main/java/org/fungover/breeze/util/Redacted.java(0 hunks)src/main/java/org/fungover/breeze/util/Strings.java(0 hunks)src/main/java/org/fungover/breeze/util/Version.java(0 hunks)src/main/java/org/fungover/breeze/util/package-info.java(0 hunks)src/main/java/org/fungover/breeze/vector/Vector2.java(0 hunks)src/main/java/org/fungover/breeze/vector/Vector3.java(0 hunks)src/main/java/org/fungover/breeze/vector/Vector4.java(0 hunks)
💤 Files with no reviewable changes (49)
- src/main/java/org/fungover/breeze/matrix/Matrix3x3.java
- src/main/java/org/fungover/breeze/util/package-info.java
- src/main/java/org/fungover/breeze/math/Vector3.java
- src/main/java/org/fungover/breeze/vector/Vector2.java
- src/main/java/org/fungover/breeze/graph/WeightedGraph.java
- src/main/java/org/fungover/breeze/math/Ray.java
- src/main/java/org/fungover/breeze/csv/CsvReader.java
- src/main/java/org/fungover/breeze/graph/Graph.java
- src/main/java/org/fungover/breeze/funclib/control/package-info.java
- src/main/java/org/fungover/breeze/simd/benchmarks/SimdBenchmarkUtils.java
- src/main/java/org/fungover/breeze/simd/SimdArrayOpsParallel.java
- src/main/java/org/fungover/breeze/vector/Vector3.java
- src/main/java/org/fungover/breeze/graph/Edge.java
- src/main/java/org/fungover/breeze/util/Arrays.java
- src/main/java/org/fungover/breeze/collection/RedBlackTree.java
- src/main/java/org/fungover/breeze/math/Quaternion.java
- src/main/java/org/fungover/breeze/util/Version.java
- src/main/java/org/fungover/breeze/control/Tuple4.java
- src/main/java/org/fungover/breeze/util/Redacted.java
- src/main/java/org/fungover/breeze/collection/FQueue.java
- src/main/java/org/fungover/breeze/control/Lazy.java
- src/main/java/org/fungover/breeze/graph/Node.java
- src/main/java/org/fungover/breeze/ascii/AsciiTableFormatter.java
- src/main/java/org/fungover/breeze/collection/Node.java
- src/main/java/org/fungover/breeze/util/PasswordGenerator.java
- src/main/java/org/fungover/breeze/collection/FSet.java
- src/main/java/org/fungover/breeze/control/Tuple3.java
- src/main/java/org/fungover/breeze/funclib/control/Try.java
- src/main/java/org/fungover/breeze/simd/SimdUtils.java
- src/main/java/org/fungover/breeze/matrix/Matrix4x4.java
- src/main/java/org/fungover/breeze/circularbuffer/CircularBuffer.java
- src/main/java/org/fungover/breeze/collection/FPriorityQueue.java
- src/main/java/org/fungover/breeze/util/Strings.java
- src/main/java/org/fungover/breeze/sql/SQL.java
- src/main/java/org/fungover/breeze/fmultimap/FMultiMap.java
- src/main/java/org/fungover/breeze/math/MathUtils.java
- src/main/java/org/fungover/breeze/graph/Dijkstra.java
- src/main/java/org/fungover/breeze/vector/Vector4.java
- src/main/java/org/fungover/breeze/control/Tuple2.java
- src/main/java/org/fungover/breeze/stringInterpolation/StringTemplate.java
- src/main/java/org/fungover/breeze/collection/FList.java
- src/main/java/org/fungover/breeze/funclib/control/Either.java
- src/main/java/org/fungover/breeze/matrix/MatrixOps.java
- src/main/java/org/fungover/breeze/util/FDeque.java
- src/main/java/org/fungover/breeze/collection/FTree.java
- src/main/java/org/fungover/breeze/math/RayMath.java
- src/main/java/org/fungover/breeze/circularbuffer/OverflowStrategy.java
- src/main/java/org/fungover/breeze/funclib/control/RetryExecutor.java
- src/main/java/org/fungover/breeze/simd/SimdArrayOps.java
🔇 Additional comments (2)
src/main/java/breeze/util/MathUtil.java (2)
1-16: AI summary inconsistent with provided code.The AI-generated summary mentions removing numerous public APIs across many packages (ascii formatting, circular buffer, collections, etc.), but the provided code only shows the addition of the new MathUtil class. This inconsistency suggests either incomplete file coverage in this review or an inaccurate summary.
10-15: Implementation is correct and efficient.The reverse method implementation follows Java best practices:
- Uses
StringBuilder.reverse(), which is the standard and efficient approach for string reversal- Properly handles null input with an explicit check and documented behavior
- Clear Javadoc describing the parameter, return value, and null-handling
However, this code should be in the
StringUtilclass as specified in the PR objectives.
| @@ -0,0 +1,16 @@ | |||
| package breeze.util; | |||
|
|
|||
| public class MathUtil { | |||
There was a problem hiding this comment.
Wrong class name: should be StringUtil, not MathUtil.
The PR objectives and Issue #140 explicitly specify that the reverse method should be added to a "StringUtil" class. String reversal is a string manipulation operation and does not belong in a class named "MathUtil," which would typically contain mathematical operations (arithmetic, trigonometry, etc.).
Apply this diff to correct the class name:
-public class MathUtil {
+public class StringUtil {Also update the filename from MathUtil.java to StringUtil.java.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public class MathUtil { | |
| public class StringUtil { |
🤖 Prompt for AI Agents
In src/main/java/breeze/util/MathUtil.java around line 3, the class is
incorrectly named MathUtil but per PR and Issue #140 it should be StringUtil;
rename the class declaration to StringUtil and move/rename the file to
src/main/java/breeze/util/StringUtil.java so filename and public class name
match, and ensure any package/import references or usages elsewhere are updated
to reference breeze.util.StringUtil.
Closes #140
Summary by CodeRabbit