package de.gymnew.sudoku.model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Sudoku {

	private Field[][] fields;
	private Row[] rows;
	private Column[] columns;
	private Block[][] blocks;

	public Sudoku() {
		fields = new Field[9][9];

		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				fields[i][j] = new Field();
			}
		}
		// TODO Create Rows, Columns and Blocks
	}

	public Field getField(int column, int row) {
		return fields[column][row];
	}

	@Override
	public Sudoku clone() {
		Sudoku sudoku = new Sudoku();
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				Field src = fields[i][j];
				Field dst = sudoku.getField(i, j);
				dst.setValue(src.getValue());
				dst.addNotes(src.getNotes());
			}
		}
		return null;
	}

	@Override
	public String toString() {
		String s = "";
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				s += fields[i][j].getValue();
			}
			s += "|";
		}
		return s;
	}

	private void load(String string) {
		// TODO Auto-generated method stub
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				string.charAt();
			}
		}
	}

	public static Sudoku load(File file) throws IOException {
		FileReader fr = new FileReader(file);
		BufferedReader br = new BufferedReader(fr);
		Sudoku s = new Sudoku();
		s.load(br.readLine());
		br.close();
		fr.close();
		return s;
	}

}

@@ -174,32 +174,60 @@
 io.FileReader;%0D%0A
+import java.io.FileWriter;%0D%0A
 import java.io.I
@@ -1618,11 +1618,161 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09public void save(File file) throws IOException%7B%0D%0A%09%09FileWriter fw = new FileWriter(file);%0D%0A%09%09fw.write(toString());%0D%0A%09%09fw.flush();%0D%0A%09%09fw.close();%0D%0A%09%7D%0D%0A
 %7D%0D%0A

add method to save a sudoku to a file