@raccoons-co/ethics
Version:
Clean code ethics.
43 lines (42 loc) • 1.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const NullPointerException_1 = __importDefault(require("./NullPointerException"));
const IllegalArgumentException_1 = __importDefault(require("./IllegalArgumentException"));
/**
* Static method to enforce a clean code ethics.
*/
class Strict {
constructor() {
// Intentionally empty.
}
/**
* Ensures that an object reference is not null.
*
* @param reference - an object reference
* @param message - an optional of the exception if the check fails
* @returns the non-null reference that was validated
* @throws NullPointerException if reference is null
*/
static notNull(reference, message) {
if (reference == null) {
throw new NullPointerException_1.default(message);
}
return reference;
}
/**
* Ensures the truth of an expression.
*
* @param expression - a boolean expression
* @param message - an optional message of the exception if check fails
* @throws IllegalArgumentException if expression is false
*/
static checkArgument(expression, message) {
if (!expression) {
throw new IllegalArgumentException_1.default(message);
}
}
}
exports.default = Strict;