class Cell {
int value;
public synchronized int getValue() {
return value;
}
public synchronized void setValue(int i) {
value = i;
}
protected synchronized void doSwap(Cell x) {
int temp = getValue();
setValue(x.getValue());
x.setValue(temp);
}
public void swap(Cell x) {
if (this == x)
return;
else if (System.identityHashCode(this)
< System.identityHashCode(x))
doSwap(x);
else
x.doSwap(this);
}
}