HibernateSimpleQueryUtils { static int getIndexOfFirstAppearanceOfAny(int startIndex, Set<Character> characters, String searchedString) { var queryCharCount = searchedString.length(); if(startIndex >= queryCharCount) { return -1; } for(var currentIndex = startIndex; currentIndex < queryCharCount; currentIndex++) { if(characters.contains(searchedString.charAt(currentIndex))) { return currentIndex; } } return -1; }  static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery); static String createLuceneQueryString(Collection<String> values, String operator,
                                                  Function<String, String> function); static String createLuceneQueryString(Collection<String> values, String operator);  }
@Test public void getIndexOfFirstAppearanceOfReturnsMinusOneWhenCharacterNotPresentAfterStartIndex() { var input = "abcd"; var characters = Set.of('b', 'f'); var startIndex = 2; var expectedIndex = -1; var actualIndex = HibernateSimpleQueryUtils.getIndexOfFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexOfFirstAppearanceOfAnyReturnsMinusOneWhenStartIndexGreaterThanInputLength() { var input = "abcd"; var characters = Set.of('b'); var startIndex = 3; var expectedIndex = -1; var actualIndex = HibernateSimpleQueryUtils.getIndexOfFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }
@Test public void getIndexOfFirstAppearanceOfAnyReturnsIndexOfFirstAppearanceAfterStartIndex() { var input = "baba"; var characters = Set.of('a', 'b'); var startIndex = 1; var expectedIndex = 1; var actualIndex = HibernateSimpleQueryUtils.getIndexOfFirstAppearanceOfAny(startIndex, characters, input); assertThat(actualIndex).isEqualTo(expectedIndex); }