Record Class Point

java.lang.Object
java.lang.Record
battleship.model.game.ocean.Point

public record Point(int x, int y) extends Record
  • Constructor Details

    • Point

      public Point(int x, int y)
      Creates an instance of a Point record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
  • Method Details

    • getRange

      public static Point[] getRange(Point startPos, Point endPos, ShipPosition.Direction direction)
      Get range of points between start and end points.
      Parameters:
      startPos - start point
      endPos - end point
      direction - ship direction
      Returns:
      array of points.
    • getLeft

      public Point getLeft()
      Returns:
      point which is on left
    • getRight

      public Point getRight()
      Returns:
      point which is on right
    • getUp

      public Point getUp()
      Returns:
      upper point
    • getDown

      public Point getDown()
      Returns:
      down point
    • getUpAndRight

      public Point getUpAndRight()
      Returns:
      up and right point
    • getDownAndRight

      public Point getDownAndRight()
      Returns:
      down and right point
    • getUpAndLeft

      public Point getUpAndLeft()
      Returns:
      up and left point
    • getDownAndLeft

      public Point getDownAndLeft()
      Returns:
      down and left point
    • equals

      public boolean equals(Object obj)
      Overridden equals method
      Specified by:
      equals in class Record
      Parameters:
      obj - object to compare
      Returns:
      true if it's equal, otherwise false.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • x

      public int x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public int y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component