Skip to content
Snippets Groups Projects
Commit b0be1169 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Change to double

parent d83b0043
Branches
No related merge requests found
package cz.vsb.java1.test2; package cz.vsb.java1.test2;
import java.util.Objects;
import cz.vsb.java1.test2.helpers.RandomGenarator; import cz.vsb.java1.test2.helpers.RandomGenarator;
public class Vector3D { public class Vector3D {
private String name; private String name;
private int x; private double x;
private int y; private double y;
private int z; private double z;
public static Vector3D generate() { public static Vector3D generate() {
return new Vector3D(RandomGenarator.generateRandomVectorName(), // name return new Vector3D(RandomGenarator.generateRandomVectorName(), // name
...@@ -34,27 +36,27 @@ public class Vector3D { ...@@ -34,27 +36,27 @@ public class Vector3D {
this.name = name; this.name = name;
} }
public int getX() { public double getX() {
return x; return x;
} }
public void setX(int x) { public void setX(double x) {
this.x = x; this.x = x;
} }
public int getY() { public double getY() {
return y; return y;
} }
public void setY(int y) { public void setY(double y) {
this.y = y; this.y = y;
} }
public int getZ() { public double getZ() {
return z; return z;
} }
public void setZ(int z) { public void setZ(double z) {
this.z = z; this.z = z;
} }
...@@ -71,15 +73,10 @@ public class Vector3D { ...@@ -71,15 +73,10 @@ public class Vector3D {
return "Vector3D [name=" + name + ", x=" + x + ", y=" + y + ", z=" + z + "]"; return "Vector3D [name=" + name + ", x=" + x + ", y=" + y + ", z=" + z + "]";
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; return Objects.hash(name, x, y, z);
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
} }
@Override @Override
...@@ -91,18 +88,9 @@ public class Vector3D { ...@@ -91,18 +88,9 @@ public class Vector3D {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Vector3D other = (Vector3D) obj; Vector3D other = (Vector3D) obj;
if (name == null) { return Objects.equals(name, other.name) && Double.doubleToLongBits(x) == Double.doubleToLongBits(other.x)
if (other.name != null) && Double.doubleToLongBits(y) == Double.doubleToLongBits(other.y)
return false; && Double.doubleToLongBits(z) == Double.doubleToLongBits(other.z);
} else if (!name.equals(other.name))
return false;
if (x != other.x)
return false;
if (y != other.y)
return false;
if (z != other.z)
return false;
return true;
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment