Record Class Vector2

java.lang.Object
java.lang.Record
com.expedient.adventofcodejade.common.Vector2
Record Components:
rowDiff - the difference in rows
colDiff - the difference in columns

public record Vector2(int rowDiff, int colDiff) extends Record
Represents a 2D vector between two Coordinates
  • Constructor Details

    • Vector2

      public Vector2(Coordinate one, Coordinate two)
    • Vector2

      public Vector2(int rowDiff, int colDiff)
      Creates an instance of a Vector2 record class.
      Parameters:
      rowDiff - the value for the rowDiff record component
      colDiff - the value for the colDiff record component
  • Method Details

    • reverse

      public Vector2 reverse()
      Reverses the direction of the Vector2
      Returns:
      vector but reversed
    • multiply

      public Vector2 multiply(int multiple)
      Multiplies the magnitude of the Vector2
      Parameters:
      multiple - magnitude
      Returns:
      the multiplied Vector2
    • apply

      public Coordinate apply(Coordinate src)
      Applies the Vector2 to a given Coordinate
      Parameters:
      src - the source Coordinate
      Returns:
      a Coordinate that is the Vector2 away from the given Coordinate
    • applyWithWraparound

      public Coordinate applyWithWraparound(Coordinate src, int rowCount, int colCount)
    • 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
    • hashCode

      public final 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
    • equals

      public final 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 the compare method from their corresponding wrapper classes.
      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.
    • rowDiff

      public int rowDiff()
      Returns the value of the rowDiff record component.
      Returns:
      the value of the rowDiff record component
    • colDiff

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