<commit_before>package ca.corefacility.bioinformatics.irida.ria.web.components.datatables;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.domain.Sort;

import ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest;

import com.google.common.base.Strings;

/**
 * Represents all parameters within a DataTables request.
 * <p>
 * <pre>
 * draw                  - Draw counter. This is used by DataTables to ensure that the Ajax returns
 *                         from server-side processing requests are drawn in sequence by DataTables.
 * start                 - Paging first record indicator. This is the start point in the current
 *                         data set (0 index based - i.e. 0 is the first record).
 * length                - Number of records that the table can display in the current draw.
 * search[value]         - Global search value. To be applied to all columns which have
 *                         searchable as true.
 * search[regex]         - true if the global filter should be treated as a regular expression for
 *                         advanced searching, false otherwise.
 * </pre>
 *
 * @see <a href="https://datatables.net/manual/server-side">Server Side</a>
 */
public class DataTablesParams {
	// This is used to match DataTables columns parameter
	// 	e.g. columns[1][name]
	//		 - matching at 1 ==> column number
	//       - matching at 2 ==> which data item (name, seachable, orderable, data)
	private static Pattern columnsPattern = Pattern.compile("columns\\[([0-9]*)?\\]\\[([a-z]*)?\\]");

	private Integer start;
	private Integer length;
	private Integer draw;
	private String searchValue;
	private List<DataTablesColumnDefinitions> dataTablesColumnDefinitions;
	private Sort sort;

	private DataTablesParams(Integer start, Integer length, Integer draw, String searchValue,
			List<DataTablesColumnDefinitions> dataTablesColumnDefinitions, Sort sort) {
		this.start = start;
		this.length = length;
		this.draw = draw;
		this.searchValue = searchValue;
		this.dataTablesColumnDefinitions = dataTablesColumnDefinitions;
		this.sort = sort;
	}

	/**
	 * Static initializer to get the params for all {@link DataTablesRequest}
	 *
	 * @param request
	 * 		{@link HttpServletRequest} request containing {@link DataTablesParams}
	 * @return {@link DataTablesParams}
	 */
	public static DataTablesParams parseDataTablesParams(HttpServletRequest request) {
		Integer start = Integer.valueOf(request.getParameter("start"));
		Integer length = Integer.valueOf(request.getParameter("length"));
		Integer draw = Integer.valueOf(request.getParameter("draw"));
		String searchValue = request.getParameter("search[value]");
		List<DataTablesColumnDefinitions> dataTablesColumnDefinitions = getColumnDefinitions(request);
		Sort sort = getColumnSortData(request, dataTablesColumnDefinitions);
		return new DataTablesParams(start, length, draw, searchValue, dataTablesColumnDefinitions, sort);
	}

	/**<commit_msg>Removed unused parameter<commit_after>package ca.corefacility.bioinformatics.irida.ria.web.components.datatables;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.domain.Sort;

import ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest;

import com.google.common.base.Strings;

/**
 * Represents all parameters within a DataTables request.
 * <p>
 * <pre>
 * draw                  - Draw counter. This is used by DataTables to ensure that the Ajax returns
 *                         from server-side processing requests are drawn in sequence by DataTables.
 * start                 - Paging first record indicator. This is the start point in the current
 *                         data set (0 index based - i.e. 0 is the first record).
 * length                - Number of records that the table can display in the current draw.
 * search[value]         - Global search value. To be applied to all columns which have
 *                         searchable as true.
 * search[regex]         - true if the global filter should be treated as a regular expression for
 *                         advanced searching, false otherwise.
 * </pre>
 *
 * @see <a href="https://datatables.net/manual/server-side">Server Side</a>
 */
public class DataTablesParams {
	// This is used to match DataTables columns parameter
	// 	e.g. columns[1][name]
	//		 - matching at 1 ==> column number
	//       - matching at 2 ==> which data item (name, seachable, orderable, data)
	private static Pattern columnsPattern = Pattern.compile("columns\\[([0-9]*)?\\]\\[([a-z]*)?\\]");

	private Integer start;
	private Integer length;
	private Integer draw;
	private String searchValue;
	private Sort sort;

	private DataTablesParams(Integer start, Integer length, Integer draw, String searchValue, Sort sort) {
		this.start = start;
		this.length = length;
		this.draw = draw;
		this.searchValue = searchValue;
		this.sort = sort;
	}

	/**
	 * Static initializer to get the params for all {@link DataTablesRequest}
	 *
	 * @param request
	 * 		{@link HttpServletRequest} request containing {@link DataTablesParams}
	 * @return {@link DataTablesParams}
	 */
	public static DataTablesParams parseDataTablesParams(HttpServletRequest request) {
		Integer start = Integer.valueOf(request.getParameter("start"));
		Integer length = Integer.valueOf(request.getParameter("length"));
		Integer draw = Integer.valueOf(request.getParameter("draw"));
		String searchValue = request.getParameter("search[value]");
		List<DataTablesColumnDefinitions> dataTablesColumnDefinitions = getColumnDefinitions(request);
		Sort sort = getColumnSortData(request, dataTablesColumnDefinitions);
		return new DataTablesParams(start, length, draw, searchValue, sort);
	}

	/**
{'fraction_non_alphanumeric': 0.09954751131221719, 'fraction_numerical': 0.0022624434389140274, 'mean_word_length': 3.5810510732790526, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '5533265', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1623, 'n_words': 516}