UNPKG

turbocommons-ts

Version:

General purpose library that implements frequently used and generic software development tasks

207 lines (206 loc) 9.3 kB
/** * TurboCommons is a general purpose and cross-language library that implements frequently used and generic software development tasks. * * Website : -> https://turboframework.org/en/libs/turbocommons * License : -> Licensed under the Apache License, Version 2.0. You may not use this file except in compliance with the License. * License Url : -> http://www.apache.org/licenses/LICENSE-2.0 * CopyRight : -> Copyright 2015 Edertone Advanded Solutions (08211 Castellar del Vallès, Barcelona). http://www.edertone.com */ import { HashMapObject } from "./HashMapObject"; /** * A 2D table structure */ export declare class TableObject { /** * Stores a list with all the column names on the table. * The values are stored as key / value where key is the column index and value the column label */ protected _columnNames: HashMapObject; /** * Stores all the table cells data. * The values are stored as key / value where key is the row and column index (r-c) and value the stored item */ protected _cells: HashMapObject; /** * Stores the number of columns on the current table instance */ protected _columnsCount: number; /** * Stores the number of rows on the current table instance */ protected _rowsCount: number; /** * TableObject is an abstraction of a 2D table with X columns and Y rows where each cell can be used to store any kind of data. * * Columns can be labeled with a textual name which can be used to access them anytime (data can be also accessed via numeric row and column indexes). * * @param rows The number of rows for the created table (Rows can be added or modified anytime later). * @param columns The number of columns to create or an array of strings containing the column labels for all of the columns that will be created (Columns can be added or modified anytime later). * * @return The constructed TableObject */ constructor(rows?: number, columns?: number | string[]); /** * Set the label to an existing table column. * * @param column An integer or a string containing the index or label for the column to which we want to assign a label * @param name The new label that will be assigned to the specified column * * @return True if the column name was correctly assigned */ setColumnName(column: number | string, name: string): boolean; /** * Define the names for the current table columns (Already defined column names will be overriden). * * @param names List of names that will be applied to the table columns. * It must have the same number of items and in the same order as the table columns. * * @return The list of column names after beign assigned */ setColumnNames(names: string[]): string[]; /** * Get a list with all the currently defined column names in the same order as they are assigned to the table. * If the table contains columns but no names are defined, a list with empty strings will be returned * * @return A list of strings with the column names */ getColumnNames(): string[]; /** * Get the defined column name for a given column index * * @param columnIndex a numeric column index * * @return The column label for the specified numeric index */ getColumnName(columnIndex: number): any; /** * Get the numeric column index from it's label * * @param name The label for an existing column * * @return The numeric index that is related to the given column label */ getColumnIndex(name: string): number; /** * Get all the elements that are located at the specified column index or label. * * @param column An integer or a string containing the index or label for the column that we want to retrieve * * @return All the table elements that belong to the required column */ getColumn(column: string | number): any[]; /** * Add the specified amount of columns to the table. * * @param number The number of columns that will be added to the table * @param names Optionally we can list all the labels to define for the new columns that will be added * @param at Defines the column index where the new columns will be inserted. Old columns that are located at the insertion point will not be deleted, they will be moved to the Right. By default all the new columns will be appended at the end of the table unless a positive value is specified here. * * @return True if the operation was successful */ addColumns(number: number, names?: string[], at?: number): boolean; /** * Fill the data on all the rows for the given column index or label * * @param column An integer or a string containing the index or label for the column that we want to fill * @param data An array with all the values that will be assigned to the table rows on the specified column. Array length must match rows number * * @return void */ setColumn(column: number | string, data: any[]): void; /** * Delete a whole column and all its related data from the table * * @param column An integer or a string containing the index or label for the column that we want to delete * * @return void */ removeColumn(column: number | string): void; /** * Get the value contained at the specified table cell * * @param row An integer containing the index for the row that we want to retrieve * @param column An integer or a string containing the index or label for the column that we want to retrieve * * @return The value for the cell located at the specified row and column or null if no data is defined for it */ getCell(row: number, column: number | string): any; /** * Set the value for a table cell * * @param row An integer containing the index for the row that we want to set * @param column An integer or a string containing the index or label for the column that we want to set * @param value The value we want to set to the specified cell. Any type is allowed, and different cells can contain values of different types. * * @return The assigned value after beign stored into the table cell */ setCell(row: number, column: number | string, value: any): any; /** * Get all the elements that are located at the specified row index * * @param row An integer containing the index for the row that we want to retrieve * * @return All the table elements that belong to the required row */ getRow(row: number): any[]; /** * Add the specified amount of rows to the table. * * @param number The number of rows that will be added to the table * @param at Defines the row index where the new rows will be inserted. Old rows that are located at the insertion point will not be deleted, they will be moved down. By default all the new rows will be appended at the bottom of the table unless a positive value is specified here. * * @return True if the operation was successful */ addRows(number: number, at?: number): boolean; /** * Fill all the data for the specified row * * @param row An integer containing the index for the row that we want to set * @param data An array with all the values that will be assigned to the table row. Array length must match columns number * * @return void */ setRow(row: number, data: any[]): void; /** * Delete a whole row and all its related data from the table * * @param row An integer containing the index for the row that we want to delete * * @return void */ removeRow(row: number): void; /** * Get the total number of rows that are currently available on this table * * @return The total number of rows on the table */ countRows(): number; /** * Get the total number of columns that are currently available on this table * * @return The total number of columns on the table */ countColumns(): number; /** * Get the total number of cells that are currently available on this table * * @return The total number of cells on the table */ countCells(): number; /** * Auxiliary method to validate that a given column index or label belongs to the current table * * @param column An integer or a string containing the index or label for the column that we want to validate * * @return A valid column index based on the specified integer or label. */ private _validateColumnIndex; /** * Auxiliary method to validate that a given row index belongs to the current table * * @param row An integer containing the index for the row that we want to validate * * @return A valid row index based on the specified integer */ private _validateRowIndex; }