Package sac.model

Record Class Point

Record Components:
x - The first coordinate.
y - The second coordinate.
All Implemented Interfaces:
Comparable<Point>

public record Point(int x, int y) extends Record implements Comparable<Point>
A two-dimension point.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Point(int x, int y)
    Creates an instance of a Point record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Perform x-major comparison.
    diff(Point other)
    Calculate the difference between two points.
    boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns a hash code value for this object.
    offset(int x, int y)
    Move this point to a new place with (x, y) as new origin.
    offset(Point origin)
    Move this point to a new place with `origin` as new origin.
    final String
    Returns a string representation of this record class.
    int
    x()
    Returns the value of the x record component.
    int
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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

    • compareTo

      public int compareTo(Point o)
      Perform x-major comparison.
      Specified by:
      compareTo in interface Comparable<Point>
      Parameters:
      o - the object to be compared.
      Returns:
      Returns whether the x coordinate of this point is larger. If they are the same, then compare the y coordinate.
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • 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
    • offset

      public Point offset(Point origin)
      Move this point to a new place with `origin` as new origin.
      Parameters:
      origin - The origin point.
      Returns:
      The new position of this point.
    • offset

      public Point offset(int x, int y)
      Move this point to a new place with (x, y) as new origin.
      Parameters:
      x - The x coordinate of the origin.
      y - The y coordinate of the origin.
      Returns:
      the new position of this point.
    • diff

      public Point diff(Point other)
      Calculate the difference between two points.
      Parameters:
      other - The point to be subtracted.
      Returns:
      The difference between two points.
    • 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