Example #1
0
        public static ITable RangeSelect(this ITable table, ObjectName columnName, SelectableRange[] ranges)
        {
            // If this table is empty then there is no range to select so
            // trivially return this object.
            if (table.RowCount == 0)
            {
                return(table);
            }

            // Are we selecting a black or null range?
            if (ranges == null || ranges.Length == 0)
            {
                // Yes, so return an empty table
                return(table.EmptySelect());
            }

            // Are we selecting the entire range?
            if (ranges.Length == 1 &&
                ranges[0].Equals(SelectableRange.FullRange))
            {
                // Yes, so return this table.
                return(table);
            }

            // Must be a non-trivial range selection.

            var t = (Table)table;

            // Find the column index of the column selected
            int column = t.FindFieldName(columnName);

            if (column == -1)
            {
                throw new Exception("Unable to find the column given to select the range of: " + columnName.Name);
            }

            // Select the range
            IList <long> rows = table.SelectRange(column, ranges);

            // Make a new table with the range selected
            VirtualTable vTable = new VirtualTable((Table)table);

            vTable.Set((Table)table, rows);

            // We know the new set is ordered by the column.
            vTable.OptimisedPostSet(column);

            return(vTable);
        }