Improve SRP by decomposing Utils.java and CSVImporter.java #913
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
I performed this refactoring as part of a small university homework assignment (HW) focusing on software design principles. The goal was to improve the code's cohesion and maintainability.
The changes address clear violations of the Single Responsibility Principle (SRP) in two utility classes:
The original Utils.java was acting as a general catch-all for math, file, and data conversion logic. I split it into specialized classes:
FileUtils.java (New):
Moved addFileExtension here.
ChartMathUtil.java (New):
Moved getTickStartOffset, pow, getGeneratedDataAsList, and getGeneratedDataAsArray here.
Utils.java (Cleaned):
This class is now focused primarily on data conversion (Array/List conversion).
This class was mixing three different responsibilities (chart assembly, file I/O, and string parsing).
FileUtils.java (Used):
Moved both getAllFiles methods here, as they are pure file system utilities.
DataConverter.java (New):
Moved the getAxisData (String to Number parsing) method here.
CSVImporter.java (Cleaned):
This class is now more focused on its main job: CSV reading and chart assembly.
I updated all the method calls in the project to point to the new utility classes and ran the Main demo in the xchart-demo module. All charts continue to work correctly.