<commit_before>﻿#region Licencia
/*
   Copyright 2013 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Northwind.Common.Collections
{
	/// <summary>
	/// Clase que representa una colección de objetos estáticos que contiene metadatos sobre sus elementos
	/// </summary>
	/// <typeparam name="T">El tipo de objeto que contiene la collección</typeparam>
	public class StaticList<T> : IStaticList<T>
	{
		/// <summary>
		/// Subconjunto de elementos de trabajo
		/// </summary>
		protected readonly List<T> Subset = new List<T>();

		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="subset"></param>
		/// <param name="offset"></param>
		/// <param name="limit"></param>
		/// <param name="totalCount"></param>
		public StaticList(IEnumerable<T> subset, int offset, int limit, long totalCount)
		{
			Verify.ArgumentNotNull(subset, "subset");
			Verify.ArgumentInRange(offset, totalCount, "offset");

			Subset = (subset.ToList() ?? new List<T>());
			TotalItemCount = totalCount;
			FirstItemOnPage = offset;
			PageSize = limit;			
			
			PageCount = (TotalItemCount > 0 ? (int)Math.Ceiling(TotalItemCount / (double)PageSize) : 0);
			PageNumber = (PageCount > 0 ? (FirstItemOnPage / PageCount) + 1 : 1);
			HasPreviousPage = (PageNumber > 1);
			HasNextPage = (PageNumber < PageCount);
			IsFirstPage = (PageNumber == 1);
			IsLastPage = (PageNumber > PageCount);
		}

		#endregion

		#region Miembros de IStaticList<T>

		/// <summary>
		/// Obtiene el elemento que se encuentra en el índice especificado
		/// </summary>
		public T this[int index]
		{
			get { return Subset[index]; }
		}

		/// <summary>
		/// Obtiene el número de elementos de <see cref="StaticList{T}"/>
		/// </summary>
		public int Count<commit_msg>Corrección en la generación del número de página<commit_after>﻿#region Licencia
/*
   Copyright 2013 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Northwind.Common.Collections
{
	/// <summary>
	/// Clase que representa una colección de objetos estáticos que contiene metadatos sobre sus elementos
	/// </summary>
	/// <typeparam name="T">El tipo de objeto que contiene la collección</typeparam>
	public class StaticList<T> : IStaticList<T>
	{
		/// <summary>
		/// Subconjunto de elementos de trabajo
		/// </summary>
		protected readonly List<T> Subset = new List<T>();

		#region Constructor

		/// <summary>
		/// 
		/// </summary>
		/// <param name="subset"></param>
		/// <param name="offset"></param>
		/// <param name="limit"></param>
		/// <param name="totalCount"></param>
		public StaticList(IEnumerable<T> subset, int offset, int limit, long totalCount)
		{
			Verify.ArgumentNotNull(subset, "subset");
			Verify.ArgumentInRange(offset, totalCount, "offset");

			Subset = (subset.ToList() ?? new List<T>());
			TotalItemCount = totalCount;
			FirstItemOnPage = offset;
			PageSize = limit;			
			
			PageCount = (TotalItemCount > 0 ? (int)Math.Ceiling(TotalItemCount / (double)PageSize) : 0);
			PageNumber = (PageCount > 0 ? (FirstItemOnPage / PageCount) - 1 : 1);
			HasPreviousPage = (PageNumber > 1);
			HasNextPage = (PageNumber < PageCount);
			IsFirstPage = (PageNumber == 1);
			IsLastPage = (PageNumber > PageCount);
		}

		#endregion

		#region Miembros de IStaticList<T>

		/// <summary>
		/// Obtiene el elemento que se encuentra en el índice especificado
		/// </summary>
		public T this[int index]
		{
			get { return Subset[index]; }
		}

		/// <summary>
		/// Obtiene el número de elementos de <see cref="StaticList{T}"/>
		/// </summary>
		public int Count
{'fraction_non_alphanumeric': 0.1246079866192766, 'fraction_numerical': 0.006272214091574326, 'mean_word_length': 3.4092165898617512, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 69, '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': '3213459', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1451, 'n_words': 474}