
public enum Color {
    NIL(-1),
    WHITE(0),
    BLACK(1);

    private final int val;

    Color(int i) {
        this.val = i;
    }

    public Color fromInt(int i) {
        for (Color c : Color.values()) {
            if (c.val == val) {
                return c;
            }
        }
        throw new IllegalArgumentException("Invalid value: " + this);

    }

    public Color inverse() {
        if (this.val == -1)
            throw new IllegalArgumentException("No inverse of NIL");
        return fromInt((this.val + 1) % 2);
    }
}
