algorithms-for-computing-li.../src/main/java/de/wwwu/awolf/model/Point.java

120 lines
2.4 KiB
Java

package de.wwwu.awolf.model;
import java.util.Objects;
import org.apache.commons.math3.util.Precision;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public class Point implements Comparable<Point> {
private static final double EPSILON = 0.00001;
private Double x;
private Double y;
private String id;
/**
* Konstruktor
*
* @param x x-Koordiante
* @param y y-Koordiante
*/
public Point(Double x, Double y) {
this.x = x;
this.y = y;
}
/**
* Konstruktor
*
* @param x x-Koordiante
* @param y y-Koordiante
* @param id id des Punkts
*/
public Point(Double x, Double y, String id) {
this.x = x;
this.y = y;
this.id = id;
}
/**
* @return x-Koordinate des Punkts
*/
public Double getX() {
return x;
}
/**
* @param x x-Koordinate des Punkts
*/
public void setX(Double x) {
this.x = x;
}
/**
* @return y-Koordinate des Punkts
*/
public Double getY() {
return y;
}
/**
* @param y y-Koordinate des Punkts
*/
public void setY(Double y) {
this.y = y;
}
@Override
public int compareTo(Point o) {
if (Precision.compareTo(this.getX(), o.getX(), EPSILON) == 0) {
return this.getY().compareTo(o.getY());
} else {
return this.getX().compareTo(o.getX());
}
}
/**
* Vergleich zweier Punkte
*
* @param obj zu vergleichernder Punkt
* @return <code>true</code> falls die Punkte gleich sind
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof Point) {
Point other = (Point) obj;
return Precision.equals(other.getX(), this.getX(), EPSILON) && Precision
.equals(other.getY(), this.getY(), EPSILON);
} else {
return super.equals(obj);
}
}
@Override
public int hashCode() {
return Objects.hash(Precision.round(x, 5), Precision.round(y, 5));
}
/**
* @return id des Punkts
*/
public String getId() {
return id;
}
/**
* @param id id des Punkts
*/
public void setId(String id) {
this.id = id;
}
}