class FilterUtil {

    private FilterUtil() {
        // utility class
    }

    private static final String LOWER_CASE = "toLowerCase";
    private static final String UPPER_CASE = "toUpperCase";

    /**
     * Verify the names of the transforms in the map.
     * @param transforms map of attribute transforms. Valid values: <code>toLowerCase, toUpperCase</code>
     * @throws UnsupportedOperationException in case of invalid transform name
     */
    public static void checkTransforms(Map<String, String> transforms) {
        Set<String> possibleTransforms = new HashSet<>(Arrays.asList(LOWER_CASE, UPPER_CASE));
        for (String transform : transforms.values()) {
            if (!possibleTransforms.contains(transform)) {
                throw new UnsupportedOperationException(String.format("invalid transform: %s", transform));
            }
        }
    }

    static String doTransform(String value, String transform) {
        switch (transform) {
            case LOWER_CASE:
                return value.toLowerCase(Locale.ROOT);
            case UPPER_CASE:
                return value.toUpperCase(Locale.ROOT);
            default:
                throw new UnsupportedOperationException(String.format("transform '%s' is unsupported", transform));
        }
    }

    /**
     * Expand attributes in filter string.
     * @param filter input string
     * @param name attribute name
     * @param value value to replace
     * @param transforms map of transformations to be potentially applied on the value
     * @return new value of the string
     */
    public static String replace(String filter, String name, String value, Map<String, String> transforms) {<FILL_FUNCTION_BODY>}

    /**
     * Replace attribute names with values in filter string.
     * @param user User object
     * @param filter filter string
     * @return filter with the values replaced
     * @see #expandUserFilter(User, String, Map)
     */
    public static String expandUserFilter(User user, String filter) {
        return expandUserFilter(user, filter, null);
    }

    /**
     * Expand {@code User} object attribute values into the filter.
     *
     * Special values are:
     * <ul>
     * <li>%username% - to be replaced with username value from the User object</li>
     * <li>%guid% - to be replaced with guid value from the User object</li>
     * </ul>
     *
     * @param user User object from the request (created by {@code UserPlugin})
     * @param filter filter
     * @param transforms map of transforms
     * @return replaced result
     */
    public static String expandUserFilter(User user, String filter, Map<String, String> transforms) {
        if (user.getUsername() != null) {
            filter = replace(filter, "username", user.getUsername(), transforms);
        }
        if (user.getId() != null) {
            filter = replace(filter, "guid", user.getId(), transforms);
        }

        return filter;
    }
}

        if (transforms != null) {
            String transform;
            if ((transform = transforms.get(name)) != null) {
                value = doTransform(value, transform);
            }
        }

        return filter.replaceAll("(?<!\\\\)%" + name + "(?<!\\\\)%", value);
    
<no_super_class>