Files
generalFunctions/helper/measurements/MeasurementBuilder.js
2025-05-26 17:09:18 +02:00

57 lines
1.1 KiB
JavaScript

const Measurement = require('./Measurement');
class MeasurementBuilder {
constructor() {
this.type = null;
this.variant = null;
this.position = null;
this.windowSize = 10; // Default window size
}
// e.g. 'pressure', 'flow', etc.
setType(type) {
this.type = type;
return this;
}
// e.g. 'predicted' or 'measured', etc..
setVariant(variant) {
this.variant = variant;
return this;
}
// Downstream or upstream of parent object
setPosition(position) {
this.position = position;
return this;
}
// default size of the data that gets tracked
setWindowSize(windowSize) {
this.windowSize = windowSize;
return this;
}
build() {
// Validate required fields
if (!this.type) {
throw new Error('Measurement type is required');
}
if (!this.variant) {
throw new Error('Measurement variant is required');
}
if (!this.position) {
throw new Error('Measurement position is required');
}
return new Measurement(
this.type,
this.variant,
this.position,
this.windowSize
);
}
}
module.exports = MeasurementBuilder;