SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/longs/Vec2lImmutable.java

53 lines
1.1 KiB
Java

package speiger.src.coreengine.math.vector.longs;
import java.util.Objects;
public class Vec2lImmutable implements Vec2l {
final long x;
final long y;
public Vec2lImmutable() {
x = 0;
y = 0;
}
public Vec2lImmutable(long value) {
x = value;
y = value;
}
public Vec2lImmutable(long x, long y) {
this.x = x;
this.y = y;
}
@Override
public boolean isMutable() { return false; }
@Override
public long getX() { return x; }
@Override
public long getY() { return y; }
@Override
public Vec2l setX(long x) { return this.x == x ? this : Vec2l.of(x, y); }
@Override
public Vec2l setY(long y) { return this.y == y ? this : Vec2l.of(x, y); }
@Override
public Vec2l copy() { return Vec2l.of(this); }
@Override
public Vec2l set(long x, long y) { return this.x == x && this.y == y ? this : Vec2l.of(x, y); }
@Override
public int hashCode() { return Objects.hash(x, y); }
@Override
public boolean equals(Object obj) {
if(obj instanceof Vec2l) {
Vec2l vec = (Vec2l)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString() { return "Vec2l[x="+x+", y="+y+"]"; }
}