class HibernateSimpleQueryUtils {

    public static String createLuceneQueryString(Collection<String> values, String operator,
                                                  Function<String, String> function) {
        if(values.isEmpty()) {
            return "";
        }

        var mappedValues = values.stream()
                .map(function)
                .distinct()
                .collect(Collectors.toList());
        var mappedValueArr = mappedValues.toArray(String[]::new);
        var firstValue = mappedValueArr[0];
        var fieldMatchStringBuilder = new StringBuilder(firstValue);

        for(var valueIndex = 1; valueIndex < mappedValueArr.length; valueIndex++) {
            fieldMatchStringBuilder
                    .append(" ")
                    .append(operator)
                    .append(" ")
                    .append(mappedValueArr[valueIndex]);
        }

        return fieldMatchStringBuilder.toString();
    }

}