public String nextName() {
    String name;

    // Do we still have names?
    if (index < names.size()) {
      // Return the next name.
      name = (String) names.get(index++);
    } else {
      // Return the next different name from the other name factory.
      do {
        name = nameFactory.nextName();
      } while (names.contains(name));
    }

    return name;
  }