You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
61 lines
1.2 KiB
package at.salento;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class Coordinate {
|
|
private int x;
|
|
|
|
private int y;
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) return true;
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
Coordinate that = (Coordinate) o;
|
|
return x == that.x && y == that.y;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(x, y);
|
|
}
|
|
|
|
public Coordinate(Coordinate c) {
|
|
this.x = c.x;
|
|
this.y = c.y;
|
|
}
|
|
|
|
public Coordinate(String s) {
|
|
if (s != null) {
|
|
String[] tokens = s.split(",");
|
|
if (tokens.length < 2) {
|
|
throw new CccException("Invalid coordinates");
|
|
}
|
|
x = Integer.parseInt(tokens[0]);
|
|
y = Integer.parseInt(tokens[1]);
|
|
|
|
} else {
|
|
throw new CccException("Invalid parameter s: " + s);
|
|
}
|
|
}
|
|
|
|
public Coordinate(int x, int y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
public int getX() {
|
|
return x;
|
|
}
|
|
|
|
public int getY() {
|
|
return y;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
String str = x + "," + y + " ";
|
|
return str;
|
|
}
|
|
|
|
}
|
|
|