protected String getUniqueName(String prompt, String originalName, boolean allowExistingName, String databaseCheck) { Method dbCheckMethod = null;
protected String getUniqueName(String originalName, boolean allowExistingName) {
  protected String getUniqueName(String prompt,                                 String originalName,                                 boolean allowExistingName,                                 String databaseCheck) {    Method dbCheckMethod = null;    String name = null;    while (true) {      // get new name from user      String inputPrompt = "Enter " + prompt + " Name";      String title = prompt + " Name";      name =         (String) JOptionPane.showInputDialog(null, inputPrompt, title,                                             JOptionPane.QUESTION_MESSAGE,                                             null, null, originalName);      if (name == null) return null;      if (name.equals(originalName) && allowExistingName)        return name;      // if name is not unique in CSMART, tell user to try again      if (contains(name)) {        title = prompt + " Name Not Unique";        int answer =           JOptionPane.showConfirmDialog(null,                                        "Use an unique name",                                        title,                                        JOptionPane.OK_CANCEL_OPTION,                                        JOptionPane.ERROR_MESSAGE);        if (answer != JOptionPane.OK_OPTION) return null;      } else {        // if name is unique in CSMART and not checking database, return name        if (databaseCheck == null)          return name;        // get the method to check for the name in the database        if (dbCheckMethod == null)          dbCheckMethod = getDatabaseCheckMethod(databaseCheck);        // ensure that name is not in the database        // if can't reach database, just assume that name is ok        boolean inDatabase = isInDatabase(name, dbCheckMethod);        if (inDatabase) {          title = prompt + " Name Not Unique";          int answer =             JOptionPane.showConfirmDialog(null,                                          "This name is in the database; use an unique name",                                          title,                                          JOptionPane.OK_CANCEL_OPTION,                                          JOptionPane.ERROR_MESSAGE);          if (answer != JOptionPane.OK_OPTION) return null;        } else          return name; // have unique name      } // end if unique in CSMART    } // end while loop  }