Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor trimIndent Method #2891

Merged
merged 2 commits into from
Feb 8, 2025
Merged

Conversation

Ryan-Dia
Copy link
Contributor

@Ryan-Dia Ryan-Dia commented Feb 6, 2025

These changes aim to make the code more maintainable and easier to understand. Please review and let me know if any further improvements are needed.

📌 Code Refactoring

  • Updated the method implementation to use Java Streams for cleaner and more concise code.
  • Enhanced exception handling with better logging to ensure stability if unexpected errors occur.
  • String Concatenation Optimization
    • Replace the current use of reduce() with Collectors.joining() to optimize performance when joining strings.
      • why? Using reduce((a, b) -> a + newLine + b) for string concatenation can be inefficient because it creates a new String object every time. Instead, using Collectors.joining(newLine) is a more efficient approach as it internally utilizes a StringBuilder to handle the concatenation process.
  • Newline Handling Improvement
    • Use the regular expression "\r?\n" for splitting the input text to support both Unix and Windows newline formats.
    • Even if the output uses "\n" consistently, handling the input correctly is necessary for robustness across different environments.
  • The original code, which used a comprehensive try-catch block for the entire method, has been modified to apply exception handling only to parts where exceptions are likely to occur. This reduces unnecessary exception handling and improves both code readability and performance.

📌 javadoc Enhancement

  • Revised the documentation to clearly state the behavior of the method.
  • Added details about how the method handles null input and specifies the return values.
  • Improved overall clarity to better communicate the intent and functionality of the method.

@bnasslahsen
Copy link
Collaborator

@Ryan-Dia,

Thank you for your contribution to the project!

@bnasslahsen bnasslahsen merged commit 567d724 into springdoc:main Feb 8, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants