Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author Tomaz Lavieri
- */
- public class Point3D<T extends Number> {
- public static final Point3D ZERO = valueOf(0,0,0);
- public static Point3D<Byte> valueOf(byte x, byte y, byte z) {
- return new Point3D<Byte>(x, y, z);
- }
- public static Point3D<Short> valueOf(short x, short y, short z) {
- return new Point3D<Short>(x, y, z);
- }
- public static Point3D<Integer> valueOf(int x, int y, int z) {
- return new Point3D<Integer>(x, y, z);
- }
- public static Point3D<Long> valueOf(long x, long y, long z) {
- return new Point3D<Long>(x, y, z);
- }
- public static Point3D<Float> valueOf(float x, float y, float z) {
- return new Point3D<Float>(x, y, z);
- }
- public static Point3D<Double> valueOf(double x, double y, double z) {
- return new Point3D<Double>(x, y, z);
- }
- private final T x;
- private final T y;
- private final T z;
- private Point3D(T x, T y, T z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public T getX() {
- return x;
- }
- public T getY() {
- return y;
- }
- public T getZ() {
- return z;
- }
- @Override
- public boolean equals(final Object other) {
- if (other == null)
- return false;
- return other instanceof Point3D && equals((Point3D) other);
- }
- public boolean equals(final Point3D other) {
- if (!this.x.equals(other.x)) {
- return false;
- }
- if (!this.y.equals(other.y)) {
- return false;
- }
- if (!this.z.equals(other.z)) {
- return false;
- }
- return true;
- }
- @Override
- public int hashCode() {
- int hash = 5;
- hash = -7 * hash + x.intValue();
- hash = 2 * hash + y.intValue();
- hash = 3 * hash + z.intValue();
- return hash;
- }
- @Override
- public String toString() {
- return "[" + x + " , " + y + " , " + z + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment