public String getNextName ( List < String > names ) { if ( names . isEmpty ( ) ) { return null ; } String name0 = names . get ( 0 ) ; if ( names . size ( ) == 1 ) { return name0 + "_1" ; } Collections . sort ( names ) ; String last = names . get ( names . size ( ) - 1 ) ; String index = last . substring ( last . lastIndexOf ( "_" ) + 1 ) ; return name0 + "_" + ( Integer . parseInt ( index ) + 1 ) ; }
Get the next distinct name based on the query result by filter of getNameFilter