SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/bytes/Vec2bImmutable.java

52 lines
1.1 KiB
Java

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