com.ui4j.api.util.Point Maven / Gradle / Ivy
The newest version!
package com.ui4j.api.util;
/**
* A point representing a location in {@code (x,y)} coordinate space,
* specified in integer precision.
*/
public class Point {
/**
* The top coordinate of this Point
.
* If no top coordinate is set it will default to 0.
*/
private int top;
/**
* The left coordinate of this Point
.
* If no left coordinate is set it will default to 0.
*/
private int left;
/**
* Constructs and initializes a point at the origin
* (0, 0) of the coordinate space.
*/
public Point() {
}
/**
* Constructs and initializes a point at the specified
* {@code (x,y)} location in the coordinate space.
* @param top the top coordinate of the newly constructed Point
* @param left the left coordinate of the newly constructed Point
*/
public Point(int top, int left) {
this.top = top;
this.left = left;
}
/**
* Returns the top coordinate of this Point
in
* int
precision.
* @return the top coordinate of this Point
.
*/
public int getTop() {
return top;
}
/**
* Sets the top coordinate of this Point
.
* @param top the top coordinate of the new location
*/
public void setTop(int top) {
this.top = top;
}
/**
* Returns the left coordinate of this Point
in
* int
precision.
* @return the left coordinate of this Point
.
*/
public int getLeft() {
return left;
}
/**
* Sets the left coordinate of this Point
.
* @param left the left coordinate of the new location
*/
public void setLeft(int left) {
this.left = left;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + left;
result = prime * result + top;
return result;
}
/**
* Determines whether or not two points are equal. Two instances of
* Point
are equal if the values of their
* left
and top
member fields, representing
* their position in the coordinate space, are the same.
* @param obj an object to be compared with this Point
* @return true
if the object to be compared is
* an instance of Point
and has
* the same values; false
otherwise.
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Point other = (Point) obj;
if (left != other.left)
return false;
if (top != other.top)
return false;
return true;
}
/**
* Returns a string representation of this point and its location
* in the {@code (x,y)} coordinate space. This method is
* intended to be used only for debugging purposes, and the content
* and format of the returned string may vary between implementations.
* The returned string may be empty but may not be null
.
*
* @return a string representation of this point
*/
@Override
public String toString() {
return "Point [top=" + top + ", left=" + left + "]";
}
}