@Test public void replaceSubstringReplacesInTheMiddleOfTheWord() { var originalString = "Oh hello there"; var replacement = "hi"; var expectedString = "Oh hi there"; var startIndex = 3; var endIndex = 7; var startEndIndexPair = Pair.of(startIndex, endIndex); var actualString = HibernateSimpleQueryUtils.replaceSubstring(startEndIndexPair, originalString, replacement); assertThat(actualString).isEqualTo(expectedString); }
static String replaceSubstring(Pair<Integer, Integer> startEndIndexPair, String stringToReplaceIn, String replacement) { var startIndex = startEndIndexPair.getFirst(); var endIndex = startEndIndexPair.getSecond(); var predReplaceSubstring = startIndex <= 1 ? "" : stringToReplaceIn.substring(0, startIndex); var succReplaceSubstring = endIndex >= (stringToReplaceIn.length() - 1) ? "" : stringToReplaceIn.substring(endIndex + 1); return String.format("%s%s%s", predReplaceSubstring, replacement, succReplaceSubstring); }
HibernateSimpleQueryUtils { static String replaceSubstring(Pair<Integer, Integer> startEndIndexPair, String stringToReplaceIn, String replacement) { var startIndex = startEndIndexPair.getFirst(); var endIndex = startEndIndexPair.getSecond(); var predReplaceSubstring = startIndex <= 1 ? "" : stringToReplaceIn.substring(0, startIndex); var succReplaceSubstring = endIndex >= (stringToReplaceIn.length() - 1) ? "" : stringToReplaceIn.substring(endIndex + 1); return String.format("%s%s%s", predReplaceSubstring, replacement, succReplaceSubstring); } }
HibernateSimpleQueryUtils { static String replaceSubstring(Pair<Integer, Integer> startEndIndexPair, String stringToReplaceIn, String replacement) { var startIndex = startEndIndexPair.getFirst(); var endIndex = startEndIndexPair.getSecond(); var predReplaceSubstring = startIndex <= 1 ? "" : stringToReplaceIn.substring(0, startIndex); var succReplaceSubstring = endIndex >= (stringToReplaceIn.length() - 1) ? "" : stringToReplaceIn.substring(endIndex + 1); return String.format("%s%s%s", predReplaceSubstring, replacement, succReplaceSubstring); }  }
HibernateSimpleQueryUtils { static String replaceSubstring(Pair<Integer, Integer> startEndIndexPair, String stringToReplaceIn, String replacement) { var startIndex = startEndIndexPair.getFirst(); var endIndex = startEndIndexPair.getSecond(); var predReplaceSubstring = startIndex <= 1 ? "" : stringToReplaceIn.substring(0, startIndex); var succReplaceSubstring = endIndex >= (stringToReplaceIn.length() - 1) ? "" : stringToReplaceIn.substring(endIndex + 1); return String.format("%s%s%s", predReplaceSubstring, replacement, succReplaceSubstring); }  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); }
HibernateSimpleQueryUtils { static String replaceSubstring(Pair<Integer, Integer> startEndIndexPair, String stringToReplaceIn, String replacement) { var startIndex = startEndIndexPair.getFirst(); var endIndex = startEndIndexPair.getSecond(); var predReplaceSubstring = startIndex <= 1 ? "" : stringToReplaceIn.substring(0, startIndex); var succReplaceSubstring = endIndex >= (stringToReplaceIn.length() - 1) ? "" : stringToReplaceIn.substring(endIndex + 1); return String.format("%s%s%s", predReplaceSubstring, replacement, succReplaceSubstring); }  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);  }