2016-07-30 22:54:46 +00:00
|
|
|
"use strict";
|
2017-08-27 18:01:06 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2017-04-09 14:29:14 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2016-09-29 20:05:20 +00:00
|
|
|
const plugins = require("./lik.plugins");
|
2016-07-30 22:54:46 +00:00
|
|
|
/**
|
|
|
|
* allows keeping track of objects
|
|
|
|
*/
|
|
|
|
class Objectmap {
|
2016-08-07 16:08:52 +00:00
|
|
|
/**
|
|
|
|
* returns a new instance
|
|
|
|
*/
|
2016-07-30 22:54:46 +00:00
|
|
|
constructor() {
|
|
|
|
this.objectArray = [];
|
2017-06-17 12:44:55 +00:00
|
|
|
// nothing here
|
2016-07-30 22:54:46 +00:00
|
|
|
}
|
2016-07-31 12:36:28 +00:00
|
|
|
/**
|
|
|
|
* add object to Objectmap
|
2017-07-05 12:29:08 +00:00
|
|
|
* returns false if the object is already in the map
|
|
|
|
* returns true if the object was added successfully
|
2016-07-31 12:36:28 +00:00
|
|
|
*/
|
2016-07-30 22:54:46 +00:00
|
|
|
add(objectArg) {
|
2017-07-05 12:29:08 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-07-30 22:54:46 +00:00
|
|
|
}
|
2016-09-22 10:00:33 +00:00
|
|
|
/**
|
|
|
|
* like .add but adds an whole array of objects
|
|
|
|
*/
|
|
|
|
addArray(objectArrayArg) {
|
|
|
|
for (let item of objectArrayArg) {
|
|
|
|
this.add(item);
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 12:36:28 +00:00
|
|
|
/**
|
|
|
|
* check if object is in Objectmap
|
|
|
|
*/
|
2016-07-30 22:54:46 +00:00
|
|
|
checkForObject(objectArg) {
|
2016-08-08 15:29:44 +00:00
|
|
|
return this.objectArray.indexOf(objectArg) !== -1;
|
2016-07-30 22:54:46 +00:00
|
|
|
}
|
2016-08-08 14:00:14 +00:00
|
|
|
/**
|
|
|
|
* find object
|
|
|
|
*/
|
|
|
|
find(findFunction) {
|
|
|
|
let resultArray = this.objectArray.filter(findFunction);
|
|
|
|
if (resultArray.length > 0) {
|
|
|
|
return resultArray[0];
|
|
|
|
}
|
2016-08-08 14:03:58 +00:00
|
|
|
else {
|
2016-09-22 10:00:33 +00:00
|
|
|
return null;
|
2016-08-08 14:03:58 +00:00
|
|
|
}
|
2016-08-08 14:00:14 +00:00
|
|
|
}
|
2016-11-19 22:54:52 +00:00
|
|
|
/**
|
|
|
|
* finds a specific element and then removes it
|
|
|
|
*/
|
|
|
|
findOneAndRemove(findFunction) {
|
|
|
|
let foundElement = this.find(findFunction);
|
|
|
|
if (foundElement) {
|
|
|
|
this.remove(foundElement);
|
|
|
|
}
|
|
|
|
return foundElement;
|
|
|
|
}
|
2016-07-31 12:36:28 +00:00
|
|
|
/**
|
|
|
|
* run function for each item in Objectmap
|
|
|
|
*/
|
|
|
|
forEach(functionArg) {
|
2017-08-27 18:01:06 +00:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
for (let object of this.objectArray) {
|
|
|
|
yield functionArg(object);
|
|
|
|
}
|
|
|
|
});
|
2016-07-31 12:36:28 +00:00
|
|
|
}
|
|
|
|
/**
|
2016-11-19 22:08:54 +00:00
|
|
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
2016-07-31 12:36:28 +00:00
|
|
|
*/
|
2016-11-19 22:08:54 +00:00
|
|
|
getOneAndRemove() {
|
|
|
|
return this.objectArray.shift();
|
|
|
|
}
|
2016-09-29 20:05:20 +00:00
|
|
|
/**
|
|
|
|
* returns a cloned array of all the objects currently in the Objectmap
|
|
|
|
*/
|
|
|
|
getArray() {
|
|
|
|
return plugins.lodash.cloneDeep(this.objectArray);
|
|
|
|
}
|
2016-11-19 22:54:52 +00:00
|
|
|
/**
|
|
|
|
* check if Objectmap ist empty
|
|
|
|
*/
|
|
|
|
isEmpty() {
|
|
|
|
if (this.objectArray.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 22:08:54 +00:00
|
|
|
/**
|
|
|
|
* 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 = [];
|
|
|
|
}
|
2016-07-30 22:54:46 +00:00
|
|
|
}
|
|
|
|
exports.Objectmap = Objectmap;
|
2018-01-27 17:11:11 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLHlDQUF5QztBQVV6Qzs7R0FFRztBQUNIO0lBR0U7O09BRUc7SUFDSDtRQ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