Strings { public static String sanitizeIdentifierName(String identifier) { if ( identifier != null && identifier.length() > 0 ) { int firstAlphabeticIndex = 0; while ( firstAlphabeticIndex < identifier.length() && ( identifier.charAt( firstAlphabeticIndex ) == UNDERSCORE || Character.isDigit( identifier.charAt( firstAlphabeticIndex ) ) ) ) { firstAlphabeticIndex++; } if ( firstAlphabeticIndex < identifier.length()) { return identifier.substring( firstAlphabeticIndex ).replace( "[]", "Array" ); } return identifier.replace( "[]", "Array" ); } return identifier; } private  Strings(); static String capitalize(String string); static String decapitalize(String string); static String join(Iterable<?> iterable, String separator); static String join(Iterable<T> iterable, String separator, Extractor<T, String> extractor); static String joinAndCamelize(Iterable<?> iterable); static boolean isEmpty(String string); static boolean isNotEmpty(String string); static String getSafeVariableName(String name, String... existingVariableNames); static String getSafeVariableName(String name, Collection<String> existingVariableNames); static String sanitizeIdentifierName(String identifier); static String stubPropertyName(String fullyQualifiedName); static String getMostSimilarWord(String word, Collection<String> similarWords);  }
@Test public void testSanitizeIdentifierName() { assertThat( Strings.sanitizeIdentifierName( "test" ) ).isEqualTo( "test" ); assertThat( Strings.sanitizeIdentifierName( "int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "_Test" ) ).isEqualTo( "Test" ); assertThat( Strings.sanitizeIdentifierName( "_int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "__int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "test_" ) ).isEqualTo( "test_" ); assertThat( Strings.sanitizeIdentifierName( "___" ) ).isEqualTo( "___" ); assertThat( Strings.sanitizeIdentifierName( "_0Test" ) ).isEqualTo( "Test" ); assertThat( Strings.sanitizeIdentifierName( "_0123456789Test" ) ).isEqualTo( "Test" ); assertThat( Strings.sanitizeIdentifierName( "_0int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "__0int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "___0" ) ).isEqualTo( "___0" ); }