Add Java implementation of COBOL merge sort program #31
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.
Java Implementation of COBOL merge_sort_test.cbl Program
Summary
This PR implements a complete Java port of the COBOL
merge_sort_test.cblprogram, creating four core Java classes that replicate the exact functionality and output format of the original COBOL version.Key Components Added:
CustomerRecord.java: Data structure with fixed-width field formatting (customerID: 5 digits, lastName/firstName: 50 chars each, contractID: 5 digits, comment: 25 chars)FileReader.java&FileWriter.java: Handle fixed-width record I/O with exact COBOL file format compatibilityMergeSortProcessor.java: Main program implementing merge (ascending customerID) and sort (descending contractID) operationsCritical Fix Applied: The initial implementation produced records with trailing spaces (136 chars vs COBOL's 120 chars). Fixed by trimming output records and updating the parser to handle variable-length input records.
Verification Status: All output files now produce byte-for-byte identical results between COBOL and Java versions, confirmed via
diffcomparison.Review & Testing Checklist for Human
Recommended Test Plan:
rm *.txt && rm java/*.txtcd merge_sort && ./merge_sort_testcd java && java MergeSortProcessordiff ../test-file-1.txt test-file-1.txt(repeat for all 4 files)wc -c *.txt ../*.txtDiagram
%%{ init : { "theme" : "default" }}%% graph TB COBOL["merge_sort_test.cbl<br/>(Original COBOL)"]:::context Main["MergeSortProcessor.java<br/>(Main Program)"]:::major-edit Record["CustomerRecord.java<br/>(Data Structure)"]:::major-edit Reader["FileReader.java<br/>(File Input)"]:::major-edit Writer["FileWriter.java<br/>(File Output)"]:::major-edit TestFile1["test-file-1.txt"]:::context TestFile2["test-file-2.txt"]:::context MergeOutput["merge-output.txt"]:::context SortedOutput["sorted-contract-id.txt"]:::context Main -->|"generates test data"| Writer Writer --> TestFile1 Writer --> TestFile2 Main -->|"reads input files"| Reader Reader --> TestFile1 Reader --> TestFile2 Main -->|"writes merged results"| Writer Writer --> MergeOutput Main -->|"writes sorted results"| Writer Writer --> SortedOutput Record -->|"used by all components"| Main Record --> Reader Record --> Writer subgraph Legend L1["Major Edit"]:::major-edit L2["Minor Edit"]:::minor-edit L3["Context/No Edit"]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
diffTechnical Details: