code: public static String checkSameName( List<String> strings, String string ) {
          int index = 1;
          for( int i = 0; i < strings.size(); i++ ) {
              if (index == 10000) {
                  // something odd is going on
                  throw new RuntimeException();
              }
              String existingString = strings.get(i);
              existingString = existingString.trim();
              if (existingString.trim().equals(string.trim())) {
                  // name exists, change the name of the entering
                  if (string.endsWith(")")) {
                      string = string.trim().replaceFirst("\\([0-9]+\\)$", "(" + (index++) + ")");
                  } else {
                      string = string + " (" + (index++) + ")";
                  }
                  // start again
                  i = 0;
              }
          }
          return string;
      }
docs: Checks if the list of strings supplied contains the supplied string.
  
  <p>If the string is contained it changes the name by adding a number.
  <p>The spaces are trimmed away before performing name equality.
  
  @param strings the list of existing strings.
  @param string the proposed new string, to be changed if colliding.
  @return the new non-colliding name for the string.