예제 #1
0
        public static CSVData AddRows(CSVData data, RowsType rows)
        {
            CSVData ret = new CSVData(data);

            ret.AddRows(rows);
            return(ret);
        }
예제 #2
0
 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;
        }
예제 #4
0
 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;
            }
        }
예제 #6
0
 private void ConstructRows(RowsType rows)
 {
     AddRows(rows);
 }
예제 #7
0
 public CSVData(ColsType columns, RowsType rows)
 {
     SetColumnsAndRows(columns, new RowsType());
     ConstructRows(rows);
 }
예제 #8
0
 public void SortDescending <T>(Func <Dictionary <string, string>, T> comp)
 {
     _rows = _rows.OrderByDescending(row => comp(ToDict(Cols, row))).ToList();
 }
예제 #9
0
        public void DropDuplicates(List <string> keys)
        {
            List <int> idxsToCompare = keys.Select(key => ColIdxMap[key]).ToList();

            _rows = _rows.Distinct(new ListEqualityComparer <string>(idxsToCompare)).ToList();
        }
예제 #10
0
 public void SortDescending <T>(Func <RowType, T> comp)
 {
     _rows = _rows.OrderByDescending(comp).ToList();
 }
예제 #11
0
 public void Sort <T>(Func <RowType, T> comp)
 {
     _rows = _rows.OrderBy(comp).ToList();
 }
예제 #12
0
 public void AddRows(RowsType rows)
 {
     _rows.Capacity = RowsCount + rows.Count;
     rows.ForEach(x => AddRow(x));
 }
예제 #13
0
 public void FilterInPlace(Func <Dictionary <string, string>, bool> predicate)
 {
     _rows = _rows.Where(x => predicate(ToDict(Cols, x))).ToList();
 }
예제 #14
0
 public void FilterInPlace(Func <RowType, bool> predicate)
 {
     _rows = _rows.Where(predicate).ToList();
 }