package com.tompa.sudoku;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by Tompa
 * Date: Sep 30, 2010
 */
public class Cell implements Cloneable {
    private Integer value = null; // possibilities are ignored if value is set
    private Set<Integer> possibilities = new HashSet<Integer>(9);

    public Cell() {
        for (int i = 1; i < 10; i++)
            addPossibility(i);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Cell copy = (Cell) super.clone();
        Set<Integer> possibilitiesCopy = new HashSet<Integer>(9);
        copy.setPossibilities(possibilitiesCopy);
        for (Integer possibility : possibilities) {
            possibilitiesCopy.add(possibility);
        }
        return copy;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public Set<Integer> getPossibilities() {
        return possibilities;
    }

    public void setPossibilities(Set<Integer> possibilities) {
        this.possibilities = possibilities;
    }

    public void addPossibility(Integer value) {
        possibilities.add(value);
    }

    public void removePossibility(Integer value) {
        possibilities.remove(value);
    }

    @Override
    public String toString() {
        if (value == null)
            return "0";
        return value.toString();
    }
}