// Path: src/main/java/com/github/otbproject/otbproject/util/CustomCollectors.java
// public final class CustomCollectors {
//     private CustomCollectors() {}
// 
//     public static <T> Collector<T, ?, ConcurrentHashMap.KeySetView<T, Boolean>> toConcurrentSet() {
//         return Collector.of(ConcurrentHashMap::newKeySet, ConcurrentHashMap.KeySetView::add, (c1, c2) -> {
//             c1.addAll(c2);
//             return c1;
//         });
//     }
// }


import com.github.otbproject.otbproject.database.DatabaseWrapper;
import com.github.otbproject.otbproject.util.CustomCollectors;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
package com.github.otbproject.otbproject.filter;



public class Filters {
    private Filters() {}

    public static Optional<BasicFilter> get(DatabaseWrapper db, String data, FilterType type) {
        List<Map.Entry<String, Object>> list = new ArrayList<>();
        list.add(new AbstractMap.SimpleImmutableEntry<>(FilterFields.DATA, data));
        list.add(new AbstractMap.SimpleImmutableEntry<>(FilterFields.TYPE, type.name()));
        return db.getRecord(FilterFields.TABLE_NAME, list, Filters::getFilterFromResultSet);
    }

    public static List<BasicFilter> getBasicFilters(DatabaseWrapper db) {
        Optional<List<BasicFilter>> optional = db.tableDump(FilterFields.TABLE_NAME,
                rs -> {
                    List<BasicFilter> filters = new ArrayList<>();
                    while (rs.next()) {
                        filters.add(getFilterFromResultSet(rs));
                    }
                    return filters;
                });
        return optional.orElse(Collections.emptyList());
    }

    public static ConcurrentHashMap.KeySetView<Filter, Boolean> getAllFilters(DatabaseWrapper db) {
// Path: src/main/java/com/github/otbproject/otbproject/util/CustomCollectors.java
// public final class CustomCollectors {
//     private CustomCollectors() {}
// 
//     public static <T> Collector<T, ?, ConcurrentHashMap.KeySetView<T, Boolean>> toConcurrentSet() {
//         return Collector.of(ConcurrentHashMap::newKeySet, ConcurrentHashMap.KeySetView::add, (c1, c2) -> {
//             c1.addAll(c2);
//             return c1;
//         });
//     }
// }


// Path: src/main/java/com/github/otbproject/otbproject/filter/Filters.java
import com.github.otbproject.otbproject.database.DatabaseWrapper;
import com.github.otbproject.otbproject.util.CustomCollectors;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

package com.github.otbproject.otbproject.filter;



public class Filters {
    private Filters() {}

    public static Optional<BasicFilter> get(DatabaseWrapper db, String data, FilterType type) {
        List<Map.Entry<String, Object>> list = new ArrayList<>();
        list.add(new AbstractMap.SimpleImmutableEntry<>(FilterFields.DATA, data));
        list.add(new AbstractMap.SimpleImmutableEntry<>(FilterFields.TYPE, type.name()));
        return db.getRecord(FilterFields.TABLE_NAME, list, Filters::getFilterFromResultSet);
    }

    public static List<BasicFilter> getBasicFilters(DatabaseWrapper db) {
        Optional<List<BasicFilter>> optional = db.tableDump(FilterFields.TABLE_NAME,
                rs -> {
                    List<BasicFilter> filters = new ArrayList<>();
                    while (rs.next()) {
                        filters.add(getFilterFromResultSet(rs));
                    }
                    return filters;
                });
        return optional.orElse(Collections.emptyList());
    }

    public static ConcurrentHashMap.KeySetView<Filter, Boolean> getAllFilters(DatabaseWrapper db) {
        return getBasicFilters(db).stream().map(Filter::fromBasicFilter).collect(CustomCollectors.toConcurrentSet());