/// <summary>
        /// Creates a new <see cref="Utility.ConversionTable"/> from a collection of lines.
        /// </summary>
        /// <param name="lines">A collection of lines that hold the data for a single <see cref="Utility.ConversionTable"/>.</param>
        /// <returns>A new <see cref="Utility.ConversionTable"/>.</returns>
        public ConversionTable CreateConversionTable(List <List <string> > lines)
        {
            ConversionTable table = null;

            if (lines.Count > 1 &&
                lines[0].Count >= lines.Count)
            {
                table = new ConversionTable(lines[0][0]);
                var tableHeader = lines[0].ToList();
                var indexOfFirstTrailingEmpty = tableHeader.IndexOf(tableHeader.FirstOrDefault(conversionValue => conversionValue.Equals(string.Empty)));
                var tableWidth = (indexOfFirstTrailingEmpty != -1) ? indexOfFirstTrailingEmpty : tableHeader.Count;

                for (var rowIndex = 0; rowIndex < lines.Count; ++rowIndex)
                {
                    for (var columnIndex = 0; columnIndex < tableWidth; ++columnIndex)
                    {
                        if (rowIndex == 0)
                        {
                            table.Table.AddColumn(lines[rowIndex][columnIndex]);
                        }
                        else
                        {
                            table.Table.AddValue(lines[0][columnIndex], lines[rowIndex][columnIndex]);
                        }
                    }
                }
            }

            return(table);
        }
Beispiel #2
0
        /// <summary>
        /// Checks for equality between this, and another <see cref="ConversionTable"/>;
        /// </summary>
        /// <param name="otherTable">The <see cref="ConversionTable"/> to check equality with.</param>
        /// <returns>The equality between this an another object.</returns>
        public bool Equals(ConversionTable otherTable)
        {
            var equality = true;

            if (Table.Data.Count == otherTable.Table.Data.Count &&
                Table.Data[0].Count == otherTable.Table.Data[0].Count)
            {
                for (var rowIndex = 0; rowIndex < Table.Data.Count; ++rowIndex)
                {
                    for (var columnIndex = 0; columnIndex < Table.Data[0].Count; ++columnIndex)
                    {
                        if (Table.Data[rowIndex][columnIndex] != otherTable.Table.Data[rowIndex][columnIndex])
                        {
                            equality = false;
                        }
                    }
                }
            }

            return(equality);
        }