wip
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
export class PointsTable {
|
||||
import type { IValueObject } from '@gridpilot/shared/domain';
|
||||
|
||||
export interface PointsTableProps {
|
||||
pointsByPosition: Map<number, number>;
|
||||
}
|
||||
|
||||
export class PointsTable implements IValueObject<PointsTableProps> {
|
||||
private readonly pointsByPosition: Map<number, number>;
|
||||
|
||||
constructor(pointsByPosition: Record<number, number> | Map<number, number>) {
|
||||
@@ -18,4 +24,23 @@ export class PointsTable {
|
||||
const value = this.pointsByPosition.get(position);
|
||||
return typeof value === 'number' ? value : 0;
|
||||
}
|
||||
|
||||
get props(): PointsTableProps {
|
||||
return {
|
||||
pointsByPosition: new Map(this.pointsByPosition),
|
||||
};
|
||||
}
|
||||
|
||||
equals(other: IValueObject<PointsTableProps>): boolean {
|
||||
const a = this.props.pointsByPosition;
|
||||
const b = other.props.pointsByPosition;
|
||||
|
||||
if (a.size !== b.size) return false;
|
||||
for (const [key, value] of a.entries()) {
|
||||
if (b.get(key) !== value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user