I have a method which loops over user elements, and sets a boolean value according to some given constraint:
public void checkUsers( int constraint ) {
for(int i=0; i<nodeUsers().size(); i++) {
UserElement elem = nodeUsers().getUsersElementAt(i);
switch (constraint) {
case CHECK_ALL:
elem.setChecked(true); break;
case CHECK_NONE:
elem.setChecked(false); break;
case CHECK_NO_LANG:
if (elem.getLanguage() == null)
elem.setChecked(true);
else
elem.setChecked(false);
break;
// More cases
}
}
}
I'm wondering if this solution is OK. Maybe I could better write different methods like:
public void checkAllUsers() {
for(int i=0; i<nodeUsers().size(); i++) {
UserElement elem = nodeUsers().getUsersElementAt(i);
elem.setChecked(true);
}
}
public void checkNoUsers() {
for(int i=0; i<nodeUsers().size(); i++) {
UserElement elem = nodeUsers().getUsersElementAt(i);
elem.setChecked(false);
}
}
// Edit: I've added a third case.