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 ; }
Checks if the list of strings supplied contains the supplied string .