<commit_before>package com.insanitydesign.vertx;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.vertx.java.core.logging.Logger;

import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Session;

/**
 * This serves as cache for prepared statements, implementing logic to handle new, existing and also limiting cache
 * stack sizes.
 * 
 * @author insanitydesign
 */
public class PreparedStatementCache {

	/** A concurrency safe HashMap to store all cached statements */
	private Map<String, CassandraPreparedStatement> cachedStatements = new ConcurrentHashMap<>();

	/** The max size of this cache before statements are removed */
	private int prepStmtCacheSize;

	/** The Cassandra storage connection to create prepared statements from */
	private Session session;

	/** The container logger for debugging purposes */
	private Logger logger;

	/**
	 * Initiate the cache with its max size and a logger to debug against.
	 * 
	 * @param prepStmtCacheSize
	 *            The size of this cache
	 * @param logger
	 *            The logger to use for debugging
	 */
	public PreparedStatementCache(int prepStmtCacheSize, Logger logger) {
		this.prepStmtCacheSize = prepStmtCacheSize;
		this.logger = logger;
	}

	/**
	 * Checks if a statement is already cached and returns that while also incrementing its counter. If the statement is
	 * not part of the cache, it will be added upfront.
	 * 
	 * @param statement
	 *            The CQL Statement to prepare and cache
	 * @return A PreparedStatement to fire
	 */
	public PreparedStatement addAndGet(String statement) {
		if(!contains(statement)) {
			return add(statement).useAndGet();
		}
<commit_msg>Changed: Prepared statement cache size must be at least 1<commit_after>package com.insanitydesign.vertx;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.vertx.java.core.logging.Logger;

import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Session;

/**
 * This serves as cache for prepared statements, implementing logic to handle new, existing and also limiting cache
 * stack sizes.
 * 
 * @author insanitydesign
 */
public class PreparedStatementCache {

	/** A concurrency safe HashMap to store all cached statements */
	private Map<String, CassandraPreparedStatement> cachedStatements = new ConcurrentHashMap<>();

	/** The max size of this cache before statements are removed */
	private int prepStmtCacheSize;

	/** The Cassandra storage connection to create prepared statements from */
	private Session session;

	/** The container logger for debugging purposes */
	private Logger logger;

	/**
	 * Initiate the cache with its max size and a logger to debug against.
	 * 
	 * @param prepStmtCacheSize
	 *            The size of this cache
	 * @param logger
	 *            The logger to use for debugging
	 */
	public PreparedStatementCache(int prepStmtCacheSize, Logger logger) {
		//Cache must be at least size == 1
		this.prepStmtCacheSize = (prepStmtCacheSize < 1 ? 1 : prepStmtCacheSize);
		this.logger = logger;
	}

	/**
	 * Checks if a statement is already cached and returns that while also incrementing its counter. If the statement is
	 * not part of the cache, it will be added upfront.
	 * 
	 * @param statement
	 *            The CQL Statement to prepare and cache
	 * @return A PreparedStatement to fire
	 */
	public PreparedStatement addAndGet(String statement) {
		if(!contains(statement)) {
			return add(statement).useAndGet();
		}

{'fraction_non_alphanumeric': 0.07982855612108224, 'fraction_numerical': 0.0010715242432360033, 'mean_word_length': 3.8619791666666665, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '4940243', 'n_tokens_mistral': 1043, 'n_tokens_neox': 981, 'n_words': 375}