package de.gymnew.sudoku.model;

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

public class Field {

	private byte value; // 0 = undefined
	private boolean locked;
	private Set<Byte> notes;
	private Row row;
	private Column col;
	private Block block;

	Field() {
		notes = new HashSet<Byte>();
	}

	public byte getValue() {
		return value;
	}

	public boolean canHaveValue(byte b) {
		if (b == 0) {
			return true;
		}

		if (row.hasValue(b) == false && col.hasValue(b) == false && block.hasValue(b) == false) {
			return true;
		} else
			return false;
	}

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

	public Set<Byte> getNotes() {
		return notes;
	}

	public synchronized int countNotes() {
		return notes.size();
	}

	public synchronized boolean addNote(byte b) {
		return notes.add(b);
	}

	public synchronized boolean addNotes(Collection<Byte> col) {
		return notes.addAll(col);
	}

	public synchronized boolean hasNote(byte b) {
		return notes.contains(b);
	}

	public synchronized boolean deleteNote(byte b) {
		return notes.remove(b);
	}

	public synchronized void clearNotes() {
		notes.clear();
	}

	public Row getRow() {
		return row;
	}

	public Column getColumn() {
		return col;
	}

	public Block getBlock() {
		return block;
	}

	void setRow(Row row) {
		this.row = row;
	}

	void setBlock(Block block) {
		this.block = block;
	}

	void setColumn(Column column) {
		this.col = column;
	}

	public boolean isLocked() {
		return locked;
	}

	public void setLocked(boolean locked) {
		this.locked = locked;
	}
}

@@ -721,21 +721,71 @@
 %0D%0A%09%09
-return notes;
+synchronized(notes) %7B%0D%0A%09%09%09return new HashSet%3CByte%3E(notes);%0D%0A%09%09%7D
 %0D%0A%09%7D
@@ -825,24 +825,50 @@
 tNotes() %7B%0D%0A
+%09%09synchronized(notes) %7B%0D%0A%09
 %09%09return not
@@ -875,24 +875,29 @@
 es.size();%0D%0A
+%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09publi
@@ -930,32 +930,58 @@
 Note(byte b) %7B%0D%0A
+%09%09synchronized(notes) %7B%0D%0A%09
 %09%09return notes.a
@@ -984,24 +984,29 @@
 es.add(b);%0D%0A
+%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09publi
@@ -1058,24 +1058,50 @@
 te%3E col) %7B%0D%0A
+%09%09synchronized(notes) %7B%0D%0A%09
 %09%09return not
@@ -1113,24 +1113,29 @@
 dAll(col);%0D%0A
+%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09publi
@@ -1168,32 +1168,58 @@
 Note(byte b) %7B%0D%0A
+%09%09synchronized(notes) %7B%0D%0A%09
 %09%09return notes.c
@@ -1227,24 +1227,29 @@
 ntains(b);%0D%0A
+%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09publi
@@ -1289,24 +1289,50 @@
 (byte b) %7B%0D%0A
+%09%09synchronized(notes) %7B%0D%0A%09
 %09%09return not
@@ -1342,24 +1342,29 @@
 remove(b);%0D%0A
+%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09publi
@@ -1395,24 +1395,50 @@
 rNotes() %7B%0D%0A
+%09%09synchronized(notes) %7B%0D%0A%09
 %09%09notes.clea
@@ -1439,24 +1439,29 @@
 s.clear();%0D%0A
+%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09publi

Make notes truly thread-safe