<commit_before>/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 * 
 * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package io.debezium.relational;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import org.apache.kafka.connect.data.Schema;

import io.debezium.annotation.ThreadSafe;
import io.debezium.util.Collect;
import io.debezium.util.FunctionalReadWriteLock;

/**
 * Structural definitions for a set of tables in a JDBC database.
 * 
 * @author <NAME>
 */
@ThreadSafe
public class Tables {

    /**
     * A filter for tables.
     */
    @FunctionalInterface
    public static interface TableFilter {
        /**
         * Determine whether the named table should be included.
         * 
         * @param catalogName the name of the database catalog that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param schemaName the name of the database schema that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param tableName the name of the table
         * @return {@code true} if the table should be included, or {@code false} if the table should be excluded
         */
        boolean test(String catalogName, String schemaName, String tableName);
    }

    /**
     * A filter for columns.
     */
    @FunctionalInterface
    public static interface ColumnFilter {
        /**
         * Determine whether the named column should be included in the table's {@link Schema} definition.
         * 
         * @param catalogName the name of the database catalog that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param schemaName the name of the database schema that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param tableName the name of the table
         * @param columnName the name of the column
         * @return {@code true} if the table should be included, or {@code false} if the table should be excluded
         */
        boolean test(String catalogName, String schemaName, String tableName, String columnName);
    }

    private final FunctionalReadWriteLock lock = FunctionalReadWriteLock.reentrant();
    private final Map<TableId, TableImpl> tablesByTableId = new HashMap<>();
    private final Set<TableId> changes = new HashSet<>();

    /**
     * Create an empty set of definitions.
     */
    public Tables() {
    }

    /**
     * Get the number of tables that are in this object.
     * 
     * @return the table count
     */
    public int size() {
        return lock.read(tablesByTableId::size);
    }

    public Set<TableId> drainChanges() {
        return lock.write(() -> {
            if (changes.isEmpty()) return Collections.emptySet();
            Set<TableId> result = new HashSet<>(changes);
            changes.clear();
            return result;
        });
    }

    /**
     * Add or update the definition for the identified table.
     * 
     * @param tableId the identifier of the table
     * @param columnDefs the list of column definitions; may not be null or empty
     * @param primaryKeyColumnNames the list of the column names that make up the primary key; may be null or empty
     * @return the previous table definition, or null if there was no prior table definition
     */
    public Table overwriteTable(TableId tableId, List<Column> columnDefs, List<String> primaryKeyColumnNames) {
        return lock.write(() -> {
            TableImpl updated = new TableImpl(tableId, columnDefs, primaryKeyColumnNames);
            try {
                return tablesByTableId.put(tableId, updated);
            } finally {<commit_msg>Correct return type for function<commit_after>/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 * 
 * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package io.debezium.relational;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import org.apache.kafka.connect.data.Schema;

import io.debezium.annotation.ThreadSafe;
import io.debezium.util.Collect;
import io.debezium.util.FunctionalReadWriteLock;

/**
 * Structural definitions for a set of tables in a JDBC database.
 * 
 * @author <NAME>
 */
@ThreadSafe
public class Tables {

    /**
     * A filter for tables.
     */
    @FunctionalInterface
    public static interface TableFilter {
        /**
         * Determine whether the named table should be included.
         * 
         * @param catalogName the name of the database catalog that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param schemaName the name of the database schema that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param tableName the name of the table
         * @return {@code true} if the table should be included, or {@code false} if the table should be excluded
         */
        boolean test(String catalogName, String schemaName, String tableName);
    }

    /**
     * A filter for columns.
     */
    @FunctionalInterface
    public static interface ColumnFilter {
        /**
         * Determine whether the named column should be included in the table's {@link Schema} definition.
         * 
         * @param catalogName the name of the database catalog that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param schemaName the name of the database schema that contains the table; may be null if the JDBC driver does not
         *            show a schema for this table
         * @param tableName the name of the table
         * @param columnName the name of the column
         * @return {@code true} if the table should be included, or {@code false} if the table should be excluded
         */
        boolean test(String catalogName, String schemaName, String tableName, String columnName);
    }

    private final FunctionalReadWriteLock lock = FunctionalReadWriteLock.reentrant();
    private final Map<TableId, TableImpl> tablesByTableId = new HashMap<>();
    private final Set<TableId> changes = new HashSet<>();

    /**
     * Create an empty set of definitions.
     */
    public Tables() {
    }

    /**
     * Get the number of tables that are in this object.
     * 
     * @return the table count
     */
    public int size() {
        return lock.read(tablesByTableId::size);
    }

    public Set<TableId> drainChanges() {
        return lock.write(() -> {
            if (changes.isEmpty()) return Collections.<TableId>emptySet();
            Set<TableId> result = new HashSet<>(changes);
            changes.clear();
            return result;
        });
    }

    /**
     * Add or update the definition for the identified table.
     * 
     * @param tableId the identifier of the table
     * @param columnDefs the list of column definitions; may not be null or empty
     * @param primaryKeyColumnNames the list of the column names that make up the primary key; may be null or empty
     * @return the previous table definition, or null if there was no prior table definition
     */
    public Table overwriteTable(TableId tableId, List<Column> columnDefs, List<String> primaryKeyColumnNames) {
        return lock.write(() -> {
            TableImpl updated = new TableImpl(tableId, columnDefs, primaryKeyColumnNames);
            try {
                return tablesByTableId.put(tableId, updated);
            } finally {
{'fraction_non_alphanumeric': 0.07798277982779828, 'fraction_numerical': 0.0019680196801968018, 'mean_word_length': 2.5032313657906076, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 28, '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': '7588716', 'n_tokens_mistral': 2099, 'n_tokens_neox': 2043, 'n_words': 860}