PRQuadTree / src / Point.java
Point.java
Raw
/**
 * 
 * @author nickgrifasi
 * @version 10/11/21
 *  Points class describes coordinates that will be 
 *  utilized to organize points by position in the quadTree.
 *  
 */
public class Point implements Comparable<Point> {
    
    private String name;
    private int xCord;
    private int yCord;
    
    /**
     * Constructor for Points class
     * @param pointName name of point
     * @param x X-coordinate of point
     * @param y Y-coordinate of point
     */
    public Point(String pointName, int x, int y)
    {
        name = pointName;
        xCord = x;
        yCord = y;
    }
    
    /**
     * Retrieves name of point
     * @return name of point
     */
    public String getName()
    {
        return name;
    }
    
    
    /**
     * Retrieves x coordinate of point
     * @return x coordinate of point
     */
    public int getXCord()
    {
        return xCord;
    }
    
    /**
     * Retrieves y coordinate of point
     * @return y coordinate of point
     */
    public int getYCord()
    {
        return yCord;
    }
    
    /**
     * compareTo method that compares points
     * 
     * @param compare point for comparison
     * 
     * @return integer that indicates comparison,
     * 0 --> equal, !=0, not equal
     */
    public int compareTo(Point compare)
    {
        return (compare.getXCord() - this.getXCord())
                + (compare.getYCord() - this.getYCord());
    }
    
    /**
     * returns the string representation of point
     * @return string of point
     */
    public String toString()
    {
        return "(" + name + ", " + xCord +
                ", " + yCord + ")";
    }
   
    /**
     * returns string representing of point minus the name
     * @return String of coodinates
     */
    public String toStringCoord()
    {
        return "(" + xCord + ", " + yCord + ")";
    }
    
    /**
     * Equality method for comparing Point position
     */
    @Override
    public boolean equals(Object obj)
    {
        if (obj == this) {
            return true;
        }
        
        if ((obj == null) || (obj.getClass() 
                != this.getClass())) {
            return false;
        }
        Point equal = (Point) obj;
        return (this.getXCord() == equal.getXCord() &&
                this.getYCord() == equal.getYCord());
        
        
    }
    
    
    

}