package speiger.src.coreengine.math.vector.shorts;

import java.util.Objects;

public class Vec2sImmutable implements Vec2s {
	final short x;
	final short y;
	
	public Vec2sImmutable() {
		x = 0;
		y = 0;
	}
	
	public Vec2sImmutable(short value) {
		x = value;
		y = value;
	}
	
	public Vec2sImmutable(short x, short y) {
		this.x = x;
		this.y = y;
	}
	
	@Override
	public boolean isMutable() { return false; }
	@Override
	public short x() { return x; }
	@Override
	public short y() { return y; }
	@Override
	public Vec2s x(short x) { return this.x == x ? this : Vec2s.of(x, y); }
	@Override
	public Vec2s y(short y) { return this.y == y ? this : Vec2s.of(x, y); }
	@Override
	public Vec2s copy() { return Vec2s.of(this); }
	@Override
	public Vec2s set(short x, short y) { return this.x == x && this.y == y ? this : Vec2s.of(x, y); }
	@Override
	public int hashCode() { return Objects.hash(x, y); }
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Vec2s) {
			Vec2s vec = (Vec2s)obj;
			return vec.x() == x && vec.y() == y;
		}
		return false;
	}
	
	@Override
	public String toString() { return "Vec2s[x="+x+", y="+y+"]"; }
}
