SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/shorts/Vec4sImmutable.java

69 lines
1.7 KiB
Java

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