<commit_before>package au.com.noojee.acceloapi.filter;

import au.com.noojee.acceloapi.AcceloException;
import au.com.noojee.acceloapi.filter.expressions.Eq;
import au.com.noojee.acceloapi.filter.expressions.Expression;
import au.com.noojee.acceloapi.filter.expressions.Search;

public class AcceloFilter
{
	public static final String ALL = "_ALL";

	private Expression expression = null;

	private Search search = null;

	private boolean refreshCache = false;

	/**
	 * Limits the no. of rows returned during a query.
	 * 
	 * We default to 50 (a single page) unless the caller explicitly over-rides the default.
	 */
	private int limit = 50;

	public void where(Search search) throws AcceloException
	{
		if (expression != null)
			throw new AcceloException("You may not combine filters and searches");

		this.search = search;

	}

	public void where(Expression expression) throws AcceloException
	{
		if (search != null)
			throw new AcceloException("You may not combine filters and searches");

		this.expression = expression;
	}

	public AcceloFilter and(Expression child) // throws AcceloException
	{
		this.expression = new And(this.expression, child);

		return this;
	}

	public AcceloFilter or(Expression child)
	{
		this.expression = new Or(this.expression, child);

		return this;
	}

	/**
	 * Use this method to invalid any cache data associated with this filter.
	 * This will force the system to re-fetch the data from the accelo servers.
	 */
	public void refreshCache()
	{
		this.refreshCache = true;
	}

	public boolean isRefreshCache()
	{
		return refreshCache;
	}

	/**
	 * Returns the accelo json expression for this filter.
	 * 
	 * "_filters": { "_OR" : { "email": "<EMAIL>", "email" :
	 * "<EMAIL>" } }
	 * 
	 * @param filterMap
	 * @return
	 */
	public String toJson()
	{
		String json = "";

		if (expression != null)
		{
			json += "\"_filters\": {\n";

			json += expression.toJson();

			json += "}";
		}
		else

		if (search != null)
		{
			json += "\"_search\": ";
			json += "\"" + search.getOperand() + "\"";
		}

		return json;
	}

	@Override
	public String toString()
	{
		return toJson().replaceAll("\n", " ");
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((expression == null) ? 0 : expression.hashCode());
		result = prime * result + ((search == null) ? 0 : search.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AcceloFilter other = (AcceloFilter) obj;
		if (expression == null)
		{
			if (other.expression != null)
				return false;
		}
		else if (!expression.equals(other.expression))
			return false;
		if (search == null)
		{
			if (other.search != null)
				return false;
		}
		else if (!search.equals(other.search))
			return false;
		return true;<commit_msg>Added the limit into the cache key.<commit_after>package au.com.noojee.acceloapi.filter;

import au.com.noojee.acceloapi.AcceloException;
import au.com.noojee.acceloapi.filter.expressions.Eq;
import au.com.noojee.acceloapi.filter.expressions.Expression;
import au.com.noojee.acceloapi.filter.expressions.Search;

public class AcceloFilter
{
	public static final String ALL = "_ALL";

	private Expression expression = null;

	private Search search = null;

	private boolean refreshCache = false;

	/**
	 * Limits the no. of rows returned during a query.
	 * 
	 * We default to 50 (a single page) unless the caller explicitly over-rides the default.
	 */
	private int limit = 50;

	public void where(Search search) throws AcceloException
	{
		if (expression != null)
			throw new AcceloException("You may not combine filters and searches");

		this.search = search;

	}

	public void where(Expression expression) throws AcceloException
	{
		if (search != null)
			throw new AcceloException("You may not combine filters and searches");

		this.expression = expression;
	}

	public AcceloFilter and(Expression child) // throws AcceloException
	{
		this.expression = new And(this.expression, child);

		return this;
	}

	public AcceloFilter or(Expression child)
	{
		this.expression = new Or(this.expression, child);

		return this;
	}

	/**
	 * Use this method to invalid any cache data associated with this filter.
	 * This will force the system to re-fetch the data from the accelo servers.
	 */
	public void refreshCache()
	{
		this.refreshCache = true;
	}

	public boolean isRefreshCache()
	{
		return refreshCache;
	}

	/**
	 * Returns the accelo json expression for this filter.
	 * 
	 * "_filters": { "_OR" : { "email": "<EMAIL>", "email" :
	 * "<EMAIL>" } }
	 * 
	 * @param filterMap
	 * @return
	 */
	public String toJson()
	{
		String json = "";

		if (expression != null)
		{
			json += "\"_filters\": {\n";

			json += expression.toJson();

			json += "}";
		}
		else

		if (search != null)
		{
			json += "\"_search\": ";
			json += "\"" + search.getOperand() + "\"";
		}

		return json;
	}

	@Override
	public String toString()
	{
		return toJson().replaceAll("\n", " ");
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((expression == null) ? 0 : expression.hashCode());
		result = prime * result + limit;
		result = prime * result + ((search == null) ? 0 : search.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AcceloFilter other = (AcceloFilter) obj;
		if (expression == null)
		{
			if (other.expression != null)
				return false;
		}
		else if (!expression.equals(other.expression))
			return false;
		if (limit != other.limit)
			return false;
		if (search == null)
		{
			if (other.search != null)
				return false;
		}
		else if (!search.equals(other.search))
			return false;
		return true;
{'fraction_non_alphanumeric': 0.12856185048608784, 'fraction_numerical': 0.0030170968823332216, 'mean_word_length': 3.308303249097473, 'pattern_counts': {'":': 8, '<': 7, '<?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': '3141999', 'n_tokens_mistral': 2126, 'n_tokens_neox': 1858, 'n_words': 576}