Class Vector2D

java.lang.Object
com.io7m.jtensors.core.unparameterized.vectors.Vector2D
All Implemented Interfaces:
Vector2DType, VectorReadable2DType, VectorComputationalType

public final class Vector2D extends Object implements Vector2DType
The type of 2D double-typed vectors.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builds instances of type Vector2D.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a builder for Vector2D.
    static Vector2D
    copyOf(Vector2DType instance)
    Creates an immutable copy of a Vector2DType value.
    boolean
    equals(Object another)
    This instance is equal to all instances of Vector2D that have equal attribute values.
    int
    Computes a hash code from attributes: x, y.
    static Vector2D
    of(double x, double y)
    Construct a new immutable Vector2D instance.
    Prints the immutable value Vector2D with attribute values.
    final Vector2D
    withX(double value)
    Copy the current immutable object by setting a value for the x attribute.
    final Vector2D
    withY(double value)
    Copy the current immutable object by setting a value for the y attribute.
    double
    x()
     
    double
    y()
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • x

      public double x()
      Specified by:
      x in interface Vector2DType
      Specified by:
      x in interface VectorReadable2DType
      Returns:
      The value of the x attribute
    • y

      public double y()
      Specified by:
      y in interface Vector2DType
      Specified by:
      y in interface VectorReadable2DType
      Returns:
      The value of the y attribute
    • withX

      public final Vector2D withX(double value)
      Copy the current immutable object by setting a value for the x attribute. A value strict bits equality used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for x
      Returns:
      A modified copy or the this object
    • withY

      public final Vector2D withY(double value)
      Copy the current immutable object by setting a value for the y attribute. A value strict bits equality used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for y
      Returns:
      A modified copy or the this object
    • equals

      public boolean equals(Object another)
      This instance is equal to all instances of Vector2D that have equal attribute values.
      Overrides:
      equals in class Object
      Returns:
      true if this is equal to another instance
    • hashCode

      public int hashCode()
      Computes a hash code from attributes: x, y.
      Overrides:
      hashCode in class Object
      Returns:
      hashCode value
    • toString

      public String toString()
      Prints the immutable value Vector2D with attribute values.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the value
    • of

      public static Vector2D of(double x, double y)
      Construct a new immutable Vector2D instance.
      Parameters:
      x - The value for the x attribute
      y - The value for the y attribute
      Returns:
      An immutable Vector2D instance
    • copyOf

      public static Vector2D copyOf(Vector2DType instance)
      Creates an immutable copy of a Vector2DType value. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.
      Parameters:
      instance - The instance to copy
      Returns:
      A copied immutable Vector2D instance
    • builder

      public static Vector2D.Builder builder()
      Creates a builder for Vector2D.
      Vector2D.builder()
         .setX(double) // required x
         .setY(double) // required y
         .build();
      
      Returns:
      A new Vector2D builder