package zahlen;

public class Neg implements Z {

	N n;
	
	public Neg(N pn) {
		this.n = pn;
	}
	
	@Override
	public Z add(Z that) {
		if (that instanceof Neg) {
			Neg neg = (Neg)that;
			return new Neg(this.n.add(neg.n));
		} else if (that instanceof S) {
			S s = (S)that;
			if (this.n instanceof S) {
				S tn = (S)this.n;
				return new Neg(tn.n).add(s.n);
			} else {
				return that;
			}
		} else {
			return this;
		}
	}

	@Override
	public Z mult(Z that) {
		if (that instanceof Neg) {
			Neg neg = (Neg)that;
			return this.n.mult(neg.n);
		} else if (that instanceof S) {
			S v = (S)that;
			return new Neg(this.n.mult(v));
		} else {
			return new Null();
		}
	}

	@Override
	public int value() {
		return -this.n.value();
	}
	
}