<commit_before>/*
 * Copyright 2014 Grow Bit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.turbogwt.core.http.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * A manager for {@link RequestFilter} and {@link ResponseFilter}.
 *
 * @author <NAME>
 */
public class FilterManager {

    private final List<RequestFilter> requestFilters = new ArrayList<>();
    private final List<ResponseFilter> responseFilters = new ArrayList<>();

    @SuppressWarnings("unchecked")
    private List<RequestFilter> requestFiltersCopy = Collections.EMPTY_LIST;
    @SuppressWarnings("unchecked")
    private List<ResponseFilter> responseFiltersCopy = Collections.EMPTY_LIST;

    /**
     * Register a request filter.
     *
     * @param requestFilter The request filter to be registered.
     */
    public void registerRequestFilter(RequestFilter requestFilter) {
        addRequestFilter(requestFilter);
    }

    /**
     * Register a response filter.
     *
     * @param responseFilter The response filter to be registered.
     */
    public void registerResponseFilter(ResponseFilter responseFilter) {
        addResponseFilter(responseFilter);
    }

    /**
     * Returns an immutable copy of the filters.
     *
     * @return The request filters.
     */
    public List<RequestFilter> getRequestFilters() {
        return requestFiltersCopy;
    }

    /**
     * Returns an immutable copy of the filters.
     *
     * @return The response filters.
     */
    public List<ResponseFilter> getResponseFilters() {
        return responseFiltersCopy;
    }

    private void addRequestFilter(RequestFilter requestFilter) {<commit_msg>Added registration returns to FilterManager.<commit_after>/*
 * Copyright 2014 Grow Bit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.turbogwt.core.http.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * A manager for {@link RequestFilter} and {@link ResponseFilter}.
 *
 * @author <NAME>
 */
public class FilterManager {

    private final List<RequestFilter> requestFilters = new ArrayList<>();
    private final List<ResponseFilter> responseFilters = new ArrayList<>();

    @SuppressWarnings("unchecked")
    private List<RequestFilter> requestFiltersCopy = Collections.EMPTY_LIST;
    @SuppressWarnings("unchecked")
    private List<ResponseFilter> responseFiltersCopy = Collections.EMPTY_LIST;

    /**
     * Register a request filter.
     *
     * @param requestFilter The request filter to be registered.
     *
     * @return  The {@link Registration} object, which is capable of cancelling this registration
     *          from this {@link FilterManager}.
     */
    public Registration registerRequestFilter(final RequestFilter requestFilter) {
        addRequestFilter(requestFilter);

        return new Registration() {
            @Override
            public void removeHandler() {
                removeRequestFilter(requestFilter);
            }
        };
    }

    /**
     * Register a response filter.
     *
     * @param responseFilter The response filter to be registered.
     *
     * @return  The {@link Registration} object, which is capable of cancelling this registration
     *          from this {@link FilterManager}.
     */
    public Registration registerResponseFilter(final ResponseFilter responseFilter) {
        addResponseFilter(responseFilter);

        return new Registration() {
            @Override
            public void removeHandler() {
                removeResponseFilter(responseFilter);
            }
        };
    }

    /**
     * Returns an immutable copy of the filters.
     *
     * @return The request filters.
     */
    public List<RequestFilter> getRequestFilters() {
        return requestFiltersCopy;
    }

    /**
     * Returns an immutable copy of the filters.
     *
     * @return The response filters.
     */
    public List<ResponseFilter> getResponseFilters() {
        return responseFiltersCopy;
    }

    private void addRequestFilter(RequestFilter requestFilter) {
{'fraction_non_alphanumeric': 0.08312244500681332, 'fraction_numerical': 0.003114658360911038, 'mean_word_length': 2.995334370139969, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559902', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1261, 'n_words': 446}