private static String uniqueAlgorithm(List names,String baseName,String sep){
  String newName=baseName;
  int unique=0;
  while (names.contains(newName)) {
    String ins=(sep == null ? "" : sep);
    newName=baseName + ins + String.valueOf(++unique);
  }
  names.add(newName);
  return newName;
}

private static String uniqueAlgorithm ( List names , String baseName , String sep ) { String newName = baseName ; int unique = 0 ; while ( names . contains ( newName ) ) { String ins = ( sep == null ? "" : sep ) ; newName = baseName + ins + String . valueOf ( ++ unique ) ; } names . add ( newName ) ; return newName ; }
return name generated or base name if this was ok
