tswow/tswow-scripts/data/table/Table.ts
2022-02-11 15:00:55 +01:00

37 lines
1.1 KiB
TypeScript

/*
* This file is part of tswow (https://github.com/tswow)
*
* Copyright (C) 2020 tswow <https://github.com/tswow/>
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Row } from './Row';
export abstract class Table<C, Q, R extends Row<C, Q>> {
name: string;
constructor(name: string) {
this.name = name;
}
abstract first(): R;
abstract queryAll(predicate: Q): R[];
/**
* Returns the first row matching a predicate
* @param predicate
* @param defValue
*/
query(predicate: Q): R {
return (this.queryAll(predicate))[0];
}
}