package com.forerunnergames.tools.common.geometry;

import com.forerunnergames.tools.common.Arguments;

public final class Point2D
{
  private int x;
  private int y;

  public Point2D()
  {
    x = 0;
    y = 0;
  }

  public Point2D (final int x, final int y)
  {
    this.x = x;
    this.y = y;
  }

  public int getX()
  {
    return x;
  }

  public int getY()
  {
    return y;
  }

  public void setX (final int x)
  {
    this.x = x;
  }

  public void setY (final int y)
  {
    this.y = y;
  }

  public void set (final int x, final int y)
  {
    this.x = x;
    this.y = y;
  }

  public void set (final Point2D point)
  {
    Arguments.checkIsNotNull (point, "point");

    this.x = point.getX();
    this.y = point.getY();
  }

  public Point2D add (final Point2D point)
  {
    return new Point2D (x + point.getX(), y + point.getY());
  }

  public Point2D subtract (final Point2D point)
  {
    return new Point2D (x - point.getX(), y - point.getY());
  }

  @Override
  public boolean equals (final Object o)
  {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    final Point2D point2D = (Point2D) o;

    if (x != point2D.x) return false;
    if (y != point2D.y) return false;

    return true;
  }

  @Override
  public int hashCode()
  {
    int result = x;
    result = 31 * result + y;
    return result;
  }

  @Override
  public String toString()
  {
    return String.format ("%1$s: X: %2$s | Y: %3$s", getClass().getSimpleName(), x, y);
  }
}

@@ -387,28 +387,31 @@
 %7D%0A%0A  public 
-void
+Point2D
  setX (final
@@ -437,16 +437,34 @@
 s.x = x;
+%0A%0A    return this;
 %0A  %7D%0A%0A  
@@ -466,28 +466,31 @@
 %7D%0A%0A  public 
-void
+Point2D
  setY (final
@@ -508,32 +508,50 @@
 %0A    this.y = y;
+%0A%0A    return this;
 %0A  %7D%0A%0A  public v
@@ -541,36 +541,39 @@
 ;%0A  %7D%0A%0A  public 
-void
+Point2D
  set (final int 
@@ -615,32 +615,50 @@
 %0A    this.y = y;
+%0A%0A    return this;
 %0A  %7D%0A%0A  public v
@@ -660,12 +660,15 @@
 lic 
-void
+Point2D
  set
@@ -795,16 +795,34 @@
 .getY();
+%0A%0A    return this;
 %0A  %7D%0A%0A  

Make Point2D setters chainable.