116 lines
5.5 KiB
JavaScript
116 lines
5.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const plugins = require("./lik.plugins");
|
|
/**
|
|
* allows keeping track of objects
|
|
*/
|
|
class Objectmap {
|
|
/**
|
|
* returns a new instance
|
|
*/
|
|
constructor() {
|
|
this.objectArray = [];
|
|
// nothing here
|
|
}
|
|
/**
|
|
* add object to Objectmap
|
|
* returns false if the object is already in the map
|
|
* returns true if the object was added successfully
|
|
*/
|
|
add(objectArg) {
|
|
if (this.checkForObject(objectArg)) {
|
|
// the object is already in the objectmap
|
|
return false;
|
|
}
|
|
else {
|
|
// the object is not yet in the objectmap
|
|
this.objectArray.push(objectArg);
|
|
return true;
|
|
}
|
|
}
|
|
/**
|
|
* like .add but adds an whole array of objects
|
|
*/
|
|
addArray(objectArrayArg) {
|
|
for (let item of objectArrayArg) {
|
|
this.add(item);
|
|
}
|
|
}
|
|
/**
|
|
* check if object is in Objectmap
|
|
*/
|
|
checkForObject(objectArg) {
|
|
return this.objectArray.indexOf(objectArg) !== -1;
|
|
}
|
|
/**
|
|
* find object
|
|
*/
|
|
find(findFunction) {
|
|
let resultArray = this.objectArray.filter(findFunction);
|
|
if (resultArray.length > 0) {
|
|
return resultArray[0];
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
/**
|
|
* finds a specific element and then removes it
|
|
*/
|
|
findOneAndRemove(findFunction) {
|
|
let foundElement = this.find(findFunction);
|
|
if (foundElement) {
|
|
this.remove(foundElement);
|
|
}
|
|
return foundElement;
|
|
}
|
|
/**
|
|
* run function for each item in Objectmap
|
|
*/
|
|
forEach(functionArg) {
|
|
return this.objectArray.forEach(functionArg);
|
|
}
|
|
/**
|
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
|
*/
|
|
getOneAndRemove() {
|
|
return this.objectArray.shift();
|
|
}
|
|
/**
|
|
* returns a cloned array of all the objects currently in the Objectmap
|
|
*/
|
|
getArray() {
|
|
return plugins.lodash.cloneDeep(this.objectArray);
|
|
}
|
|
/**
|
|
* check if Objectmap ist empty
|
|
*/
|
|
isEmpty() {
|
|
if (this.objectArray.length === 0) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
/**
|
|
* remove object from Objectmap
|
|
*/
|
|
remove(objectArg) {
|
|
let replacementArray = [];
|
|
for (let item of this.objectArray) {
|
|
if (item !== objectArg) {
|
|
replacementArray.push(item);
|
|
}
|
|
}
|
|
this.objectArray = replacementArray;
|
|
}
|
|
/**
|
|
* wipe Objectmap
|
|
*/
|
|
wipe() {
|
|
this.objectArray = [];
|
|
}
|
|
}
|
|
exports.Objectmap = Objectmap;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBd0M7QUFVeEM7O0dBRUc7QUFDSDtJQUdFOztPQUVHO0lBQ0g7UUFMUSxnQkFBVyxHQUFRLEVBQUUsQ0FBQTtRQU0zQixlQUFlO0lBQ2pCLENBQUM7SUFFRDs7OztPQUlHO0lBQ0gsR0FBRyxDQUFFLFNBQVk7UUFDZixFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsY0FBYyxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUMsQ0FBQztZQUNuQyx5Q0FBeUM7WUFDekMsTUFBTSxDQUFDLEtBQUssQ0FBQTtRQUNkLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLHlDQUF5QztZQUN6QyxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtZQUNoQyxNQUFNLENBQUMsSUFBSSxDQUFBO1FBQ2IsQ0FBQztJQUNILENBQUM7SUFFRDs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