vendredi 3 mars 2017

Is there a better way to write nested if statements in java

I'm writing a program where users can search for a directory, file, or both. Using checkboxes to determine what the user wants to do. Later down the road I may add another option, and the code my look ugly with all the nested if statements.

This is what I have so far:

if (directories.isSelected()) {
  if (files.isSelected()) {
    return file.isDirectory() || file.isFile();
  }
  return file.isDirectory();
} else {
  if (files.isSelected()) {
    return file.isFile();
  }
}

is there a more simpler way to do this?

Aucun commentaire:

Enregistrer un commentaire