/*
File: coordinates.js
Date: 2026-03-18
Author: klp
Workspace: SWIslandRecurnSaga2026-03-16-Stg1
Purpose: Coordinates -- a (row, col) position utility class.
         Mirrors Coordinates.java from the SWIsland Recursion Saga Java source.
*/

/**
 * Coordinates
 * ===========
 * Represents a single (row, col) position in the ocean grid.
 *
 * Mirrors Coordinates.java from the Java source exactly:
 *   - Validates that row and col are both non-negative.
 *   - Provides getRow() and getCol() accessors (no setters — immutable after construction).
 *   - toString() returns "(row, col)" matching the Java output format.
 *
 * Usage:
 *   const c = new Coordinates(3, 5);
 *   c.getRow()   // → 3
 *   c.getCol()   // → 5
 *   c.toString() // → "(3, 5)"
 */
class Coordinates {

    /**
     * Creates a new (row, col) coordinate.
     * Mirrors Coordinates(int row, int col) in Java.
     *
     * @param {number} row  Zero-based row index (must be >= 0).
     * @param {number} col  Zero-based column index (must be >= 0).
     * @throws {Error} if row or col is negative.
     */
    constructor(row, col) {
        if (row < 0 || col < 0) {
            throw new Error(
                `Coordinates: row and col must be non-negative. Got (${row}, ${col}).`
            );
        }
        this._row = row;
        this._col = col;
    }

    /**
     * Returns the row index.
     * Mirrors Coordinates.getRow() in Java.
     * @returns {number}
     */
    getRow() { return this._row; }

    /**
     * Returns the column index.
     * Mirrors Coordinates.getCol() in Java.
     * @returns {number}
     */
    getCol() { return this._col; }

    /**
     * Returns a human-readable description: "(row, col)".
     * Mirrors Coordinates.toString() in Java.
     * @returns {string}
     */
    toString() {
        return `(${this._row}, ${this._col})`;
    }

}//end class Coordinates
