A clean answer to the DailyWTF equality checking issue...
Friday, December 1, 2006 7:10:41 AM
Here's the original code:
/**
Set the value of the isRecordLocked attribute.
@param newValue is the new isRecordLocked value.
*/
public void setIsRecordLocked(Boolean newValue) {
// Update state if required.
if (isRecordLocked != null) {
if (newValue == null || !isRecordLocked.equals(newValue)) {
context.setDirty(true);
}
}
else if (newValue != null) {
context.setDirty(true);
}
// Change the value.
isRecordLocked = newValue;
}
And here's the cleaner implementation:
public void setIsRecordLocked(Boolean newValue) {
if (newValue == null) {
context.setDirty(isRecordLocked != null);
} else {
context.setDirty(!newValue.equals(isRecordLocked));
}
isRecordLocked = newValue;
}
Actually, at the first glance I found myself in a mind freeze situation. But then in a a few minutes I came up with the cleaner solution.









Anonymous # Saturday, December 2, 2006 4:14:09 AM
Anonymous # Sunday, December 3, 2006 12:51:44 AM
Behrang Saeedzadehbehrangsa # Sunday, December 3, 2006 2:28:48 PM
Anonymous # Sunday, December 3, 2006 8:10:41 PM