<commit_before>﻿using System;
using System.Collections.Generic;
using Premotion.Mansion.Core.Conversion;

namespace Premotion.Mansion.Core.Data.Clauses
{
	/// <summary>
	/// 	Implements the query part for paging.
	/// </summary>
	public class PagingClause : NodeQueryClause
	{
		#region Nested type: PagingClauseInterpreter
		/// <summary>
		/// 	Interprets <see cref = "PagingClause" />.
		/// </summary>
		public class PagingClauseInterpreter : QueryInterpreter
		{
			#region Constructors
			/// <summary>
			/// </summary>
			public PagingClauseInterpreter(IConversionService conversionService) : base(10)
			{
				// validate arguments
				if (conversionService == null)
					throw new ArgumentNullException("conversionService");

				// set values
				this.conversionService = conversionService;
			}
			#endregion
			#region Interpret Methods
			/// <summary>
			/// 	Interprets the input.
			/// </summary>
			/// <param name = "context">The <see cref = "IMansionContext" />.</param>
			/// <param name = "input">The input which to interpret.</param>
			/// <returns>Returns the interpreted result.</returns>
			protected override IEnumerable<NodeQueryClause> DoInterpret(IMansionContext context, IPropertyBag input)
			{
				// validate arguments
				if (context == null)
					throw new ArgumentNullException("context");
				if (input == null)
					throw new ArgumentNullException("input");

				// check the input
				string pageNumberString;
				if (!input.TryGetAndRemove(context, "pageNumber", out pageNumberString) || string.IsNullOrEmpty(pageNumberString) || !pageNumberString.IsNumber())
					yield break;
				string pageSizeString;
				if (!input.TryGetAndRemove(context, "pageSize", out pageSizeString) || string.IsNullOrEmpty(pageSizeString) || !pageSizeString.IsNumber())
					yield break;

				// get the values
				var pageNumber = conversionService.Convert<int>(context, pageNumberString);
				var pageSize = conversionService.Convert<int>(context, pageSizeString);

				// create the paging clause
				yield return new PagingClause(pageNumber, pageSize);
			}
			#endregion
			#region Private Fields
			private readonly IConversionService conversionService;
			#endregion
		}
		#endregion
		#region Constructors
		/// <summary>
		/// 	Constructs a paging clause.
		/// </summary>
		/// <param name = "pageNumber">The number of page</param>
		/// <param name = "pageSize">The page size.</param>
		public PagingClause(int pageNumber, int pageSize)
		{
			// set value
			PageNumber = pageNumber;
			PageSize = pageSize;
		}
		#endregion
		#region Properties
		/// <summary>
		/// 	Gets the page number.<commit_msg>#22 PagingClause does not remove pageSize when pageNumber is null<commit_after>﻿using System;
using System.Collections.Generic;
using Premotion.Mansion.Core.Conversion;

namespace Premotion.Mansion.Core.Data.Clauses
{
	/// <summary>
	/// 	Implements the query part for paging.
	/// </summary>
	public class PagingClause : NodeQueryClause
	{
		#region Nested type: PagingClauseInterpreter
		/// <summary>
		/// 	Interprets <see cref = "PagingClause" />.
		/// </summary>
		public class PagingClauseInterpreter : QueryInterpreter
		{
			#region Constructors
			/// <summary>
			/// </summary>
			public PagingClauseInterpreter(IConversionService conversionService) : base(10)
			{
				// validate arguments
				if (conversionService == null)
					throw new ArgumentNullException("conversionService");

				// set values
				this.conversionService = conversionService;
			}
			#endregion
			#region Interpret Methods
			/// <summary>
			/// 	Interprets the input.
			/// </summary>
			/// <param name = "context">The <see cref = "IMansionContext" />.</param>
			/// <param name = "input">The input which to interpret.</param>
			/// <returns>Returns the interpreted result.</returns>
			protected override IEnumerable<NodeQueryClause> DoInterpret(IMansionContext context, IPropertyBag input)
			{
				// validate arguments
				if (context == null)
					throw new ArgumentNullException("context");
				if (input == null)
					throw new ArgumentNullException("input");

				// check the input
				string pageNumberString;
				var hasPageNumber = !(input.TryGetAndRemove(context, "pageNumber", out pageNumberString) || string.IsNullOrEmpty(pageNumberString) || !pageNumberString.IsNumber());
				string pageSizeString;
				var hasPageSize = !(input.TryGetAndRemove(context, "pageSize", out pageSizeString) || string.IsNullOrEmpty(pageSizeString) || !pageSizeString.IsNumber());
				if (!(hasPageNumber && hasPageSize))
					yield break;

				// get the values
				var pageNumber = conversionService.Convert<int>(context, pageNumberString);
				var pageSize = conversionService.Convert<int>(context, pageSizeString);

				// create the paging clause
				yield return new PagingClause(pageNumber, pageSize);
			}
			#endregion
			#region Private Fields
			private readonly IConversionService conversionService;
			#endregion
		}
		#endregion
		#region Constructors
		/// <summary>
		/// 	Constructs a paging clause.
		/// </summary>
		/// <param name = "pageNumber">The number of page</param>
		/// <param name = "pageSize">The page size.</param>
		public PagingClause(int pageNumber, int pageSize)
		{
			// set value
			PageNumber = pageNumber;
			PageSize = pageSize;
		}
		#endregion
		#region Properties
		/// <summary>
		/// 	Gets the page number.
{'fraction_non_alphanumeric': 0.11949451774763055, 'fraction_numerical': 0.0011150343802267236, 'mean_word_length': 3.488740617180984, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '3518332', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1553, 'n_words': 401}