package fr.loicdelorme.followUpYourGarden.core.models;

/**
 * This class allow you to create a two dimensional position.
 * 
 * @author DELORME Loïc
 * @version 1.0.0
 */
public class Position implements Comparable<Position>
{
	/**
	 * The X coordinate.
	 */
	private final int x;

	/**
	 * The Y coordinate.
	 */
	private final int y;

	/**
	 * The group of plants id.
	 */
	private final int groupOfPlantsId;

	/**
	 * Create a two dimensional position.
	 * 
	 * @param x
	 *            A X coordinate.
	 * @param y
	 *            A Y coordinate.
	 * @param groupOfPlantsId
	 *            A group of plants id.
	 */
	public Position(int x, int y, int groupOfPlantsId)
	{
		this.x = x;
		this.y = y;
		this.groupOfPlantsId = groupOfPlantsId;
	}

	/**
	 * Test if two positions have same coordinates.
	 * 
	 * @param position
	 *            A position.
	 * @return True if they have the same coordinates, else False.
	 */
	public boolean areCoordinatesEquals(Position position)
	{
		return ((this.x == position.x) && (this.y == position.y));
	}

	/**
	 * Get the X coordinate.
	 * 
	 * @return The X coordinate.
	 */
	public int getX()
	{
		return this.x;
	}

	/**
	 * Get the Y coordinate.
	 * 
	 * @return The Y coordinate.
	 */
	public int getY()
	{
		return this.y;
	}

	/**
	 * Get the group of plants id.
	 * 
	 * @return The group of plants id.
	 */
	public int getGroupOfPlantsId()
	{
		return this.groupOfPlantsId;
	}

	@Override
	public String toString()
	{
		StringBuilder representation = new StringBuilder();

		representation.append("{X : ").append(this.x).append(", Y : ").append(this.y).append(", groupOfPlantsId : ").append(this.groupOfPlantsId).append("}");

		return representation.toString();
	}

	@Override
	public boolean equals(Object object)
	{
		if (this == object)
			return true;

		if (object == null)
			return false;

		if (!(object instanceof Position))
			return false;

		Position position = (Position) object;

		if (this.x != position.x)
			return false;

		if (this.y != position.y)
			return false;

		if (this.groupOfPlantsId != position.groupOfPlantsId)
			return false;

		return true;
	}

	@Override
	public int hashCode()
	{
		return (this.x + this.y + this.groupOfPlantsId);
	}

	@Override
	public int compareTo(Position position)
	{
		int result = this.x - position.x;

		if (result != 0)
			return result;

		result = this.y - position.y;

		return result;
	}
}

@@ -1883,16 +1883,21 @@
 bject)%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -1904,16 +1904,21 @@
 n true;%0D
+%0A%09%09%7D%0D
 %0A%0D%0A%09%09if 
@@ -1935,16 +1935,21 @@
  null)%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -1949,32 +1949,37 @@
 %09%09return false;%0D
+%0A%09%09%7D%0D
 %0A%0D%0A%09%09if (!(objec
@@ -2003,16 +2003,21 @@
 tion))%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -2021,24 +2021,29 @@
 turn false;%0D
+%0A%09%09%7D%0D
 %0A%0D%0A%09%09Positio
@@ -2106,16 +2106,21 @@
 ion.x)%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -2120,32 +2120,37 @@
 %09%09return false;%0D
+%0A%09%09%7D%0D
 %0A%0D%0A%09%09if (this.y 
@@ -2165,16 +2165,21 @@
 ion.y)%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -2183,24 +2183,29 @@
 turn false;%0D
+%0A%09%09%7D%0D
 %0A%0D%0A%09%09if (thi
@@ -2252,16 +2252,21 @@
 ntsId)%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -2274,16 +2274,21 @@
  false;%0D
+%0A%09%09%7D%0D
 %0A%0D%0A%09%09ret
@@ -2519,16 +2519,21 @@
  != 0)%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -2542,16 +2542,21 @@
 result;%0D
+%0A%09%09%7D%0D
 %0A%0D%0A%09%09res

format code.