<commit_before>//-----------------------------------------------------------------------
// <copyright file="ItemsTable.cs" company="OxyPlot">
//     http://oxyplot.codeplex.com, license: Ms-PL
// </copyright>
//-----------------------------------------------------------------------

namespace OxyPlot.Reporting
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;

    /// <summary>
    /// Represents a table of items.
    /// </summary>
    public class ItemsTable : Table
    {
        #region Constants and Fields

        /// <summary>
        ///   The items.
        /// </summary>
        private IEnumerable items;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ItemsTable"/> class.
        /// </summary>
        /// <param name="itemsInRows">
        /// The items in rows.
        /// </param>
        public ItemsTable(bool itemsInRows = true)
        {
            this.Fields = new List<ItemsTableField>();
            this.ItemsInRows = itemsInRows;
            this.Alignment = Alignment.Center;
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets Alignment.
        /// </summary>
        public Alignment Alignment { get; set; }

        /// <summary>
        ///   Gets or sets Fields.
        /// </summary>
        public IList<ItemsTableField> Fields { get; set; }

        /// <summary>
        ///   Gets or sets the items.
        ///   The table will be filled when this property is set.
        /// </summary>
        /// <value>The items.</value>
        public IEnumerable Items
        {
            get
            {
                return this.items;
            }

            set
            {
                this.items = value;
                this.UpdateItems();
            }
        }

        /// <summary>
        ///   Gets a value indicating whether ItemsInRows.
        /// </summary>
        public bool ItemsInRows { get; private set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The has header.
        /// </summary>
        /// <returns>
        /// The has header.
        /// </returns>
        public bool HasHeader()
        {
            foreach (ItemsTableField c in this.Fields)
            {
                if (c.Header != null)
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// The to array.
        /// </summary>
        /// <returns>
        /// </returns>
        public string[,] ToArray()
        {
            List<object> items = this.Items.Cast<object>().ToList();
            int nrows = items.Count;

            bool hasHeader = this.HasHeader();
            if (hasHeader)
            {
                nrows++;
            }

            var result = new string[nrows, this.Fields.Count];

            int row = 0;
            if (hasHeader)
            {
                for (int i = 0; i < this.Fields.Count; i++)
                {
                    ItemsTableField c = this.Fields[i];
                    result[row, i] = c.Header;
                }

                row++;
            }

            foreach (object item in items)
            {
                for (int i = 0; i < this.Fields.Count; i++)
                {
                    ItemsTableField c = this.Fields[i];
                    string text = c.GetText(item, this.Report.ActualCulture);
                    result[row, i] = text;
                }

                row++;
            }

            if (!this.ItemsInRows)
            {
                result = Transpose(result);
            }

            return result;
        }

        /// <summary>
        /// The update items.
        /// </summary>
        public void UpdateItems()
        {
            this.Rows.Clear();
            this.Columns.Clear();
            if (this.Fields == null || this.Fields.Count == 0)
            {
                Debug.WriteLine("ItemsTable: Fields are not defined.");
                return;<commit_msg>Report.ItemsTable: corrected bug - updating items in the Update() method<commit_after>//-----------------------------------------------------------------------
// <copyright file="ItemsTable.cs" company="OxyPlot">
//     http://oxyplot.codeplex.com, license: Ms-PL
// </copyright>
//-----------------------------------------------------------------------

namespace OxyPlot.Reporting
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;

    /// <summary>
    /// Represents a table of items.
    /// </summary>
    public class ItemsTable : Table
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ItemsTable"/> class.
        /// </summary>
        /// <param name="itemsInRows">
        /// The items in rows.
        /// </param>
        public ItemsTable(bool itemsInRows = true)
        {
            this.Fields = new List<ItemsTableField>();
            this.ItemsInRows = itemsInRows;
            this.Alignment = Alignment.Center;
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets Alignment.
        /// </summary>
        public Alignment Alignment { get; set; }

        /// <summary>
        ///   Gets or sets Fields.
        /// </summary>
        public IList<ItemsTableField> Fields { get; set; }

        /// <summary>
        ///   Gets or sets the items.
        ///   The table will be filled when this property is set.
        /// </summary>
        /// <value>The items.</value>
        public IEnumerable Items { get; set; }

        /// <summary>
        ///   Gets a value indicating whether ItemsInRows.
        /// </summary>
        public bool ItemsInRows { get; private set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The has header.
        /// </summary>
        /// <returns>
        /// The has header.
        /// </returns>
        public bool HasHeader()
        {
            foreach (var c in this.Fields)
            {
                if (c.Header != null)
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// The to array.
        /// </summary>
        /// <returns>
        /// </returns>
        public string[,] ToArray()
        {
            List<object> items = this.Items.Cast<object>().ToList();
            int nrows = items.Count;

            bool hasHeader = this.HasHeader();
            if (hasHeader)
            {
                nrows++;
            }

            var result = new string[nrows, this.Fields.Count];

            int row = 0;
            if (hasHeader)
            {
                for (int i = 0; i < this.Fields.Count; i++)
                {
                    ItemsTableField c = this.Fields[i];
                    result[row, i] = c.Header;
                }

                row++;
            }

            foreach (var item in items)
            {
                for (int i = 0; i < this.Fields.Count; i++)
                {
                    ItemsTableField c = this.Fields[i];
                    string text = c.GetText(item, this.Report.ActualCulture);
                    result[row, i] = text;
                }

                row++;
            }

            if (!this.ItemsInRows)
            {
                result = Transpose(result);
            }

            return result;
        }

        /// <summary>
        /// The update.
        /// </summary>
        public override void Update()
        {
            base.Update();
            this.UpdateItems();
        }

        /// <summary>
        /// The update items.
        /// </summary>
        public void UpdateItems()
        {
            this.Rows.Clear();
            this.Columns.Clear();
            if (this.Fields == null || this.Fields.Count == 0)
            {
                Debug.WriteLine("ItemsTable: Fields are not defined.");
                return;
{'fraction_non_alphanumeric': 0.15180607224288972, 'fraction_numerical': 0.0009600384015360614, 'mean_word_length': 1.014016433059449, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 73, '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': '3128550', 'n_tokens_mistral': 2136, 'n_tokens_neox': 2022, 'n_words': 536}