コード例 #1
0
 public void TestFromStartAndCount4A()
 {
     Assert.Throws(typeof(ArgumentOutOfRangeException), () =>
     {
         var r = ContiguousIntegerRange.FromStartAndCount(0, -1);
     });
 }
コード例 #2
0
        /// <summary>
        /// Decomposes a column into repeat units by analysing the values of the column with increasing index.
        /// If a column value is repeated, the current range is finalized and a new range is started. At the end,
        /// a list of index ranges is returned. Inside each range the column values are guaranteed to be unique.
        /// </summary>
        /// <param name="col">Column to decompose.</param>
        /// <returns>List of integer ranges. Inside a single range the column values are ensured to be unique.</returns>
        public static IList <ContiguousIntegerRange> DecomposeIntoRepeatUnits(DataColumn col)
        {
            var result    = new List <ContiguousIntegerRange>();
            var alreadyIn = new HashSet <AltaxoVariant>();

            var currentRangeStart = 0;
            var currentRangeCount = 0;

            for (int i = 0; i < col.Count; i++)
            {
                if (alreadyIn.Contains(col[i]))
                {
                    alreadyIn.Clear();
                    result.Add(ContiguousIntegerRange.FromStartAndCount(currentRangeStart, currentRangeCount));
                    currentRangeStart = i;
                    currentRangeCount = 0;
                }

                alreadyIn.Add(col[i]);
                currentRangeCount++;
            }

            if (currentRangeCount > 0)
            {
                result.Add(ContiguousIntegerRange.FromStartAndCount(currentRangeStart, currentRangeCount));
            }

            return(result);
        }
コード例 #3
0
        public void TestFromStartAndCount3()
        {
            var r = ContiguousIntegerRange.FromStartAndCount(int.MaxValue, 0);

            Assert.IsTrue(r.IsEmpty);
            Assert.AreEqual(0, r.Count);
            Assert.AreEqual(0, r.LongCount);
            Assert.AreEqual(0, r.Start);
        }
コード例 #4
0
ファイル: EditCommands.cs プロジェクト: olesar/Altaxo
        /// <summary>
        /// Remove the selected columns, rows or property columns.
        /// </summary>
        public static void RemoveSelected(IWorksheetController ctrl)
        {
            using (var suspendToken = ctrl.DataTable.SuspendGetToken())
            {
                // Property columns are only deleted, if selected alone or in conjunction with data row selection
                if (ctrl.SelectedPropertyColumns.Count > 0 && ctrl.SelectedPropertyRows.Count == 0 && ctrl.SelectedDataColumns.Count == 0)
                {
                    ctrl.DataTable.PropCols.RemoveColumns(ctrl.SelectedPropertyColumns);
                    ctrl.SelectedPropertyColumns.Clear();
                    ctrl.SelectedPropertyRows.Clear();
                }
                // note here: Property rows are only removed indirect by removing data columns

                // delete the selected columns if there are _only selected columns
                if (ctrl.SelectedDataColumns.Count > 0 && ctrl.SelectedDataRows.Count == 0)
                {
                    ctrl.DataTable.RemoveColumns(ctrl.SelectedDataColumns);
                    ctrl.SelectedDataColumns.Clear(); // now the columns are deleted, so they cannot be selected
                }

                // if rows are selected, remove them in all selected columns or in all columns (if no column selection=
                if (ctrl.SelectedDataRows.Count > 0)
                {
                    ctrl.DataTable.DataColumns.RemoveRowsInColumns(
                        ctrl.SelectedDataColumns.Count > 0 ? (IAscendingIntegerCollection)ctrl.SelectedDataColumns : ContiguousIntegerRange.FromStartAndCount(0, ctrl.DataTable.DataColumns.ColumnCount),
                        ctrl.SelectedDataRows);

                    ctrl.SelectedDataColumns.Clear();
                    ctrl.SelectedDataRows.Clear();
                }

                // end code for the selected rows
                suspendToken.Dispose();
            }

            ctrl.TableAreaInvalidate(); // necessary because we changed the selections
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataTableMultipleColumnProxy"/> class. The selected collections determine which columns and rows contribute to this instance.
        /// The group number is determined by the first selected column (or, if no column is selected, by the first column of the data table).
        /// </summary>
        /// <param name="identifier">The identifier of the bundle of columns that are initially set with this constructor.</param>
        /// <param name="table">The underlying table.</param>
        /// <param name="selectedDataRows">The selected data rows.</param>
        /// <param name="selectedDataColumns">The selected data columns.</param>
        /// <exception cref="System.ArgumentNullException">table must not be null.</exception>
        public DataTableMultipleColumnProxy(string identifier, DataTable table, IAscendingIntegerCollection selectedDataRows, IAscendingIntegerCollection selectedDataColumns)
        {
            if (null == identifier)
            {
                throw new ArgumentNullException("identifier");
            }

            if (null == table)
            {
                throw new ArgumentNullException("table");
            }

            _dataColumnBundles = new Dictionary <string, ColumnBundleInfo>();

            _dataTable = new DataTableProxy(table)
            {
                ParentObject = this
            };

            _groupNumber = 0;

            if (null != selectedDataColumns && selectedDataColumns.Count > 0)
            {
                _groupNumber = table.DataColumns.GetColumnGroup(table[selectedDataColumns[0]]);
            }

            var bundle = new ColumnBundleInfo();

            _dataColumnBundles.Add(identifier, bundle);

            int maxRowCount = 0;

            if (selectedDataColumns != null && selectedDataColumns.Count > 0)
            {
                for (int i = 0; i < selectedDataColumns.Count; ++i)
                {
                    var col = table[selectedDataColumns[i]];
                    if (table.DataColumns.GetColumnGroup(col) == _groupNumber)
                    {
                        InternalAddDataColumnNoClone(bundle, ReadableColumnProxyBase.FromColumn(col));
                        maxRowCount = Math.Max(maxRowCount, col.Count);
                    }
                }
            }
            else // nothing selected - use all columns of group number 0
            {
                for (int i = 0; i < table.DataColumnCount; ++i)
                {
                    var col = table[i];
                    if (table.DataColumns.GetColumnGroup(col) == _groupNumber)
                    {
                        InternalAddDataColumnNoClone(bundle, ReadableColumnProxyBase.FromColumn(col));
                        maxRowCount = Math.Max(maxRowCount, col.Count);
                    }
                }
            }

            _useAllAvailableDataRows = null == selectedDataRows || selectedDataRows.Count == 0;

            _participatingDataRows = new AscendingIntegerCollection(_useAllAvailableDataRows ? ContiguousIntegerRange.FromStartAndCount(0, maxRowCount) : selectedDataRows);
        }