UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

95 lines (94 loc) 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BooleanValue = void 0; const Types_js_1 = require("../type/Types.js"); const LogicalValue_js_1 = require("./LogicalValue.js"); class BooleanValue { constructor(value) { this.booleanValue = value; } static of(value) { if (value === true) { return this.TRUE_VALUE; } else if (value === false) { return this.FALSE_VALUE; } throw new Error(`Cannot get boolean value of ${value}`); } getValue() { return this.booleanValue; } getType() { return Types_js_1.Type.BOOLEAN; } static true() { return BooleanValue.of(true); } static false() { return BooleanValue.of(false); } static isBoolean(val) { return typeof val === "boolean"; } isTrue() { return this.booleanValue === true; } isFalse() { return this.booleanValue === false; } compareTo(other) { return this.booleanValue ? (other.booleanValue ? 0 : 1) : -1; } toString() { return this.booleanValue ? "TRUE" : "FALSE"; } static isBooleanValueType(arg) { return typeof arg.booleanValue === "boolean"; } and(other) { if (other instanceof LogicalValue_js_1.LogicalValue) { return other.and(this); } return BooleanValue.of(this.booleanValue && other.booleanValue); } or(other) { if (other instanceof LogicalValue_js_1.LogicalValue) { return other.or(this); } return BooleanValue.of(this.booleanValue || other.booleanValue); } xor(other) { if (other instanceof LogicalValue_js_1.LogicalValue) { return other.xor(this); } return BooleanValue.of(this.booleanValue != other.booleanValue); } implies(other) { if (other instanceof LogicalValue_js_1.LogicalValue) { if (other.isUnknown()) { return (this.isFalse() ? LogicalValue_js_1.LogicalValue.true() : LogicalValue_js_1.LogicalValue.unknown()); } else { return LogicalValue_js_1.LogicalValue.of(!this.booleanValue || other.getValue()); } } return BooleanValue.of(!this.booleanValue || other.booleanValue); } not() { return this.isTrue() ? BooleanValue.false() : BooleanValue.true(); } equals(other) { if (LogicalValue_js_1.LogicalValue.isLogicalValueType(other)) { return this.booleanValue === other.getValue(); } else if (BooleanValue.isBooleanValueType(other)) { return this.booleanValue === other.booleanValue; } return false; } } exports.BooleanValue = BooleanValue; BooleanValue.TRUE_VALUE = new BooleanValue(true); BooleanValue.FALSE_VALUE = new BooleanValue(false); //# sourceMappingURL=BooleanValue.js.map