Skip to content

Conversation

@devin-ai-integration
Copy link

Migrate COBOL Merge Sort to Java

Summary

This PR implements a Java version of the COBOL merge sort program found in merge_sort/merge_sort_test.cbl. The Java implementation replicates the exact functionality and output format of the original COBOL program, including:

  • Customer record structure: 5-digit customer ID, 50-char last/first names, 5-digit contract ID, 25-char comment
  • Test data generation: Creates the same 11 customer records across two input files
  • Merge operation: Combines two input files and sorts by customer ID (ascending)
  • Sort operation: Sorts the merged file by contract ID (descending)
  • File output: Generates merge-output.txt and sorted-contract-id.txt with identical formatting

The implementation uses a Customer class with proper field formatting and two main operations that mirror the COBOL merge and sort statements.

Review & Testing Checklist for Human

  • Compare output files: Run both COBOL and Java versions and verify merge-output.txt and sorted-contract-id.txt are identical
  • Verify record formatting: Check that Customer.toString() produces exact COBOL field widths (5+50+50+5+25 characters)
  • Test edge cases: Try with empty/null fields, strings longer than field limits, and invalid data
  • Validate sorting logic: Confirm merge sorts by customer ID ascending and final sort by contract ID descending
  • Package structure review: Ensure the Java package structure (com.cognition.cobol.mergesort) is appropriate for the repository

Recommended test plan:

  1. Run the original COBOL program and save outputs
  2. Run java com.cognition.cobol.mergesort.MergeSortExample
  3. Compare all generated files byte-for-byte
  4. Test with modified input data to verify sorting behavior

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    COBOL["merge_sort/merge_sort_test.cbl"]:::context
    Customer["java-merge-sort/com/cognition/<br/>cobol/mergesort/Customer.java"]:::major-edit
    Main["java-merge-sort/com/cognition/<br/>cobol/mergesort/MergeSortExample.java"]:::major-edit
    README["java-merge-sort/README.md"]:::major-edit
    
    TestFile1["test-file-1.txt"]:::minor-edit
    TestFile2["test-file-2.txt"]:::minor-edit
    MergeOutput["merge-output.txt"]:::minor-edit
    SortedOutput["sorted-contract-id.txt"]:::minor-edit
    
    COBOL -->|"replicates functionality"| Main
    Main -->|"uses"| Customer
    Main -->|"creates"| TestFile1
    Main -->|"creates"| TestFile2
    Main -->|"generates"| MergeOutput
    Main -->|"generates"| SortedOutput
    
    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

- Created Customer class matching COBOL record structure
- Implemented merge operation sorting by customer ID ascending
- Implemented sort operation sorting by contract ID descending
- Added comprehensive README with usage instructions
- Replicates exact functionality of merge_sort_test.cbl

Co-Authored-By: Ameen <ameen.mirdamadi@gmail.com>
@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