public static CSVData AddRows(CSVData data, RowsType rows) { CSVData ret = new CSVData(data); ret.AddRows(rows); return(ret); }
public void ReorderColumns(List <string> keys) { if (!keys.All(Cols.Contains)) { string message = String.Format("ReorderColumns: keys({0}) to reorder are not a subset of CSVData ({1})", String.Join(",", keys), String.Join(",", Cols)); throw new ArgumentOutOfRangeException(nameof(keys), message); } else if (keys.Count != keys.Distinct().Count()) { string message = String.Format("ReorderColumns: keys({0}) cannot contain duplicates", String.Join(",", keys)); throw new ArgumentOutOfRangeException(nameof(keys), message); } else { List <int> oldIdxs = keys.Select(x => ColIdxMap[x]).ToList(); _columns = keys; _rows = _rows.Select(row => { var newRow = new List <string>(); oldIdxs.ForEach(idx => { newRow.Add(row[idx]); }); return(newRow); }).ToList(); } }
public TablesRow(string[] Values, int[] GridSpan, int[] VerticalMerge, RowsType Type, int JoinToRow = 0) { this.Type = Type; this.Values = Values; this.ColumnsCount = Values != null?Values.Count() : 1; this.GridSpan = GridSpan; this.VerticalMerge = VerticalMerge; this.JoinToRow = JoinToRow; }
private void SetColumnsAndRows(ColsType columns, RowsType rows) { if (columns.Count != columns.Distinct().Count()) { string message = String.Format("CSVData CSVData: duplicate column names found in input ({0})", String.Join(",", columns)); throw new ArgumentOutOfRangeException(nameof(columns), message); } _columns = columns.Select(x => x).ToList(); _rows = rows.Select(x => x).ToList(); _columnsIdxMap = new Dictionary <string, int>(); ConstructColIdxMap(); }
public TablesRow(string[] Values, int[] GridSpan, RowsType Type, int JoinToRow = 0) { this.Type = Type; this.Values = Values; this.ColumnsCount = Values != null?Values.Count() : 1; this.GridSpan = GridSpan; this.JoinToRow = JoinToRow; this.VerticalMerge = new int[this.ColumnsCount]; for (int i = 0; i < this.ColumnsCount; i++) { this.VerticalMerge[i] = 0; } }
private void ConstructRows(RowsType rows) { AddRows(rows); }
public CSVData(ColsType columns, RowsType rows) { SetColumnsAndRows(columns, new RowsType()); ConstructRows(rows); }
public void SortDescending <T>(Func <Dictionary <string, string>, T> comp) { _rows = _rows.OrderByDescending(row => comp(ToDict(Cols, row))).ToList(); }
public void DropDuplicates(List <string> keys) { List <int> idxsToCompare = keys.Select(key => ColIdxMap[key]).ToList(); _rows = _rows.Distinct(new ListEqualityComparer <string>(idxsToCompare)).ToList(); }
public void SortDescending <T>(Func <RowType, T> comp) { _rows = _rows.OrderByDescending(comp).ToList(); }
public void Sort <T>(Func <RowType, T> comp) { _rows = _rows.OrderBy(comp).ToList(); }
public void AddRows(RowsType rows) { _rows.Capacity = RowsCount + rows.Count; rows.ForEach(x => AddRow(x)); }
public void FilterInPlace(Func <Dictionary <string, string>, bool> predicate) { _rows = _rows.Where(x => predicate(ToDict(Cols, x))).ToList(); }
public void FilterInPlace(Func <RowType, bool> predicate) { _rows = _rows.Where(predicate).ToList(); }