Skip to content

Conversation

@devin-ai-integration
Copy link

Convert COBOL Merge Sort to Java Implementation

Summary

This PR adds a Java implementation of the existing COBOL merge sort program in merge_sort/merge_sort_test.cbl. The Java version replicates the exact functionality and output format of the COBOL program:

Key Components Added:

  • Customer.java - Record class with fixed-width string formatting (135 chars per record)
  • MergeSortJava.java - Main program implementing the same 3-phase workflow as COBOL
  • README.md - Documentation comparing both implementations

Program Flow (identical to COBOL):

  1. Generate test data files (6 east region + 5 west region customer records)
  2. Merge files by ascending customer ID → merge-output.txt
  3. Sort merged file by descending contract ID → sorted-contract-id.txt

Output Verification: diff command shows zero differences between COBOL and Java console output and generated files.

Review & Testing Checklist for Human

  • Critical: Run both programs side-by-side - Execute ./merge_sort_test and java MergeSortJava to verify outputs are truly identical
  • Validate fixed-width parsing logic - Check Customer.fromFixedWidthString() substring indices: (0,5), (5,55), (55,105), (105,110), (110,135) against COBOL record definition
  • Test with modified data - Try changing a customer record in COBOL to verify Java handles different data correctly
  • Verify file contents match exactly - Compare test-file-1.txt, test-file-2.txt, merge-output.txt, sorted-contract-id.txt between both implementations
  • Test sort orders - Confirm merge produces ascending customer ID order and sort produces descending contract ID order

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    COBOL["merge_sort_test.cbl<br/>Original COBOL Program"]:::context
    CustomerJava["Customer.java<br/>Record Class"]:::major-edit
    MergeSortJava["MergeSortJava.java<br/>Main Program"]:::major-edit
    README["README.md<br/>Documentation"]:::major-edit
    
    TestFile1["test-file-1.txt<br/>East Region Data"]:::context
    TestFile2["test-file-2.txt<br/>West Region Data"]:::context
    MergeOutput["merge-output.txt<br/>Merged by Customer ID"]:::context
    SortOutput["sorted-contract-id.txt<br/>Sorted by Contract ID"]:::context
    
    COBOL -->|"generates"| TestFile1
    COBOL -->|"generates"| TestFile2
    COBOL -->|"creates"| MergeOutput
    COBOL -->|"creates"| SortOutput
    
    MergeSortJava -->|"uses"| CustomerJava
    MergeSortJava -->|"replicates behavior"| COBOL
    MergeSortJava -->|"generates identical"| TestFile1
    MergeSortJava -->|"generates identical"| TestFile2
    
    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:#FFFFFF
Loading

Notes

  • Fixed-width formatting is critical - Each customer record is exactly 135 characters with specific field widths matching COBOL's pic clauses
  • Test data is hardcoded - Both implementations use identical hardcoded customer records for reproducible testing
  • File-based operations - Unlike typical Java collections-based sorting, this maintains COBOL's file I/O approach for authentic behavior replication
  • Error handling - Java version uses System.exit(1) to match COBOL's error behavior

Link to Devin run: https://app.devin.ai/sessions/470daf8b12904ef09f63ccce7ad52515
Requested by: @schaudhry123

- Created Customer.java class with fixed-width formatting
- Created MergeSortJava.java main program replicating COBOL logic
- Implemented identical test data generation (6 east + 5 west records)
- File-based merge operation by ascending customer ID
- File-based sort operation by descending contract ID
- Output matches COBOL program exactly (verified with diff)
- Added comprehensive README documenting both implementations

Co-Authored-By: Samir Chaudhry <[email protected]>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

1 participant