Package sac.model
Record Class Point
java.lang.Object
java.lang.Record
sac.model.Point
- Record Components:
x
- The first coordinate.y
- The second coordinate.
- All Implemented Interfaces:
Comparable<Point>
A two-dimension point.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Perform x-major comparison.Calculate the difference between two points.boolean
Indicates whether some other object is "equal to" this one.int
hashCode()
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.Move this point to a new place with `origin` as new origin.final String
toString()
Returns a string representation of this record class.int
x()
Returns the value of thex
record component.int
y()
Returns the value of they
record component.
-
Constructor Details
-
Method Details
-
compareTo
Perform x-major comparison.- Specified by:
compareTo
in interfaceComparable<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
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 '=='. -
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. -
offset
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
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
Calculate the difference between two points.- Parameters:
other
- The point to be subtracted.- Returns:
- The difference between two points.
-
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. -
x
public int x()Returns the value of thex
record component.- Returns:
- the value of the
x
record component
-
y
public int y()Returns the value of they
record component.- Returns:
- the value of the
y
record component
-