Package com.iizix

Class Position

java.lang.Object
com.iizix.Position
All Implemented Interfaces:
Serializable, Cloneable

public class Position extends Object implements Cloneable, Serializable
A position with integers.
Author:
Christopher Mindus
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    The X position.
    int
    The Y position.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a position initialized to 0,0.
    Position(int x, int y)
    Constructs and initializes position.
    Constructs and initializes position.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Compares to position by first X, then Y.
    boolean
    Check for equality.
    int
    Hash code.
    Creates the string representation of this position.

    Methods inherited from class java.lang.Object

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

    • x

      public int x
      The X position.
    • y

      public int y
      The Y position.
  • Constructor Details

    • Position

      public Position()
      Constructs a position initialized to 0,0.
    • Position

      public Position(int x, int y)
      Constructs and initializes position.
      Parameters:
      x - The X position.
      y - The Y position.
    • Position

      public Position(Position p)
      Constructs and initializes position.
      Parameters:
      p - The position to clone.
  • Method Details

    • equals

      public boolean equals(Object o)
      Check for equality.
      Overrides:
      equals in class Object
      Parameters:
      o - Another object.
      Returns:
      true if it's the same Position object values, false otherwise.
    • hashCode

      public int hashCode()
      Hash code.
      Overrides:
      hashCode in class Object
      Returns:
      Returns the hash code.
    • toString

      public String toString()
      Creates the string representation of this position.
      Overrides:
      toString in class Object
      Returns:
      Position String as "className[x=NN,y=NN]".
    • compare

      public static int compare(Position p1, Position p2)
      Compares to position by first X, then Y.
      Parameters:
      p1 - Position 1 (null allowed).
      p2 - Position 2 (null allowed).
      Returns:
      1 if p1 is "larger" than p2 (or p2 is null), -1 if "smaller" (or p2 is null), 0 if equal (both null).