public String createUniqueName ( String name ) { if ( ! isDuplicateName ( name ) ) { return name ; } if ( name . matches ( ".*\\(\\d*\\)" ) ) { //$NON-NLS-1$ final int start = name . lastIndexOf ( ' ' ) ; final int end = name . lastIndexOf ( ' ' ) ; final String stringInt = name . substring ( start + 1 , end ) ; final int numericValue = Integer . parseInt ( stringInt ) ; final String newName = name . substring ( 0 , start + 1 ) + ( numericValue + 1 ) + ")" ; //$NON-NLS-1$ return createUniqueName ( newName ) ; } return createUniqueName ( name + " (1)" ) ; //$NON-NLS-1$ }
Compares the given name against current names and adds the appropriate numerical suffix to ensure that it is unique .