<commit_before>package com.bugsnag.util;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
 * Decorates a map, and alters the return value of {@link #get(Object)} if the key matches a filter.
 */
public class FilteredMap implements Map<String, Object> {

    private static final String FILTERED_PLACEHOLDER = "[FILTERED]";

    private final Map<String, Object> map;
    private final Collection<String> keyFilters = new ArrayList<String>();

    public FilteredMap(Map<String, Object> map, Collection<String> keyFilters) {
        this.map = map;
        this.keyFilters.addAll(keyFilters);
    }

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public boolean isEmpty() {
        return map.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return map.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return values().contains(value);
    }

    @Override
    public Object get(Object key) {
        Object obj = map.get(key);
        return obj != null ? transformEntry(key, obj) : null;
    }

    @Override
    public Object put(String key, Object value) {
        return map.put(key, value);
    }

    @Override
    public Object remove(Object key) {
        return map.remove(key);
    }

    @Override
    public void putAll(Map<? extends String, ?> mapValues) {
        map.putAll(mapValues);
    }

    @Override
    public void clear() {
        map.clear();
    }

    @Override
    public Set<String> keySet() {
        return map.keySet();
    }

    @Override
    public Collection<Object> values() {
        Collection<Object> objects = new ArrayList<Object>();

        for (Entry<String, Object> entry : entrySet()) {
            objects.add(entry.getValue());
        }
        return objects;
    }

    @Override
    public Set<Entry<String, Object>> entrySet() {
        Set<Entry<String, Object>> entries = map.entrySet();

        for (Entry<String, Object> entry : entries) {
            String key = entry.getKey();
            entry.setValue(transformEntry(key, entry.getValue()));
        }
        return entries;
    }

    private Object transformEntry(Object key, Object value) {
        if (value instanceof Map) {
            //noinspection unchecked<commit_msg>copy entry set to avoid mutating original map<commit_after>package com.bugsnag.util;


import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Decorates a map, and alters the return value of {@link #get(Object)} if the key matches a filter.
 */
public class FilteredMap implements Map<String, Object> {

    private static final String FILTERED_PLACEHOLDER = "[FILTERED]";

    private final Map<String, Object> map;
    private final Collection<String> keyFilters = new ArrayList<String>();

    public FilteredMap(Map<String, Object> map, Collection<String> keyFilters) {
        this.map = map;
        this.keyFilters.addAll(keyFilters);
    }

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public boolean isEmpty() {
        return map.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return map.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return values().contains(value);
    }

    @Override
    public Object get(Object key) {
        Object obj = map.get(key);
        return obj != null ? transformEntry(key, obj) : null;
    }

    @Override
    public Object put(String key, Object value) {
        return map.put(key, value);
    }

    @Override
    public Object remove(Object key) {
        return map.remove(key);
    }

    @Override
    public void putAll(Map<? extends String, ?> mapValues) {
        map.putAll(mapValues);
    }

    @Override
    public void clear() {
        map.clear();
    }

    @Override
    public Set<String> keySet() {
        return map.keySet();
    }

    @Override
    public Collection<Object> values() {
        Collection<Object> objects = new ArrayList<Object>();

        for (Entry<String, Object> entry : entrySet()) {
            objects.add(entry.getValue());
        }
        return objects;
    }

    @Override
    public Set<Entry<String, Object>> entrySet() {
        Set<Entry<String, Object>> entries = map.entrySet();
        Set<Entry<String, Object>> copy = new HashSet<Entry<String, Object>>();
        copy.addAll(entries);

        for (Entry<String, Object> entry : copy) {
            String key = entry.getKey();
            entry.setValue(transformEntry(key, entry.getValue()));
        }
        return copy;
    }

    private Object transformEntry(Object key, Object value) {
        if (value instanceof Map) {
            //noinspection unchecked
{'fraction_non_alphanumeric': 0.11321138211382113, 'fraction_numerical': 0.0, 'mean_word_length': 2.5175125089349537, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4566', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1369, 'n_words': 383}