question: public static String createFreshVariable ( Set < String > vars , String var ) { String fresh = var ; while ( vars . contains ( fresh ) ) { String valFree = fresh . replaceAll ( "[^0-9]" , "" ) ; int value = valFree . equals ( "" ) ? 0 : Integer . parseInt ( valFree ) ; fresh = fresh . replaceAll ( "\\d+" , "" ) + ( ++ value ) ; } return fresh ; }
target:  generate a fresh variable avoiding global variables and variables from the same query