now checking correctly if Stringmap is empty

This commit is contained in:
2016-07-23 04:39:42 +02:00
parent 24df2fd54f
commit 6d22ee466f
9 changed files with 158 additions and 12 deletions

View File

@ -1,2 +1,3 @@
import "typings-global";
export import q = require("q");
export import q = require("q");
export import minimatch = require("minimatch");

View File

@ -3,8 +3,14 @@ import * as plugins from "./lik.plugins";
/**
* allows you to easily keep track of a bunch of strings;
*/
export interface triggerFunction {
():boolean;
}
export class Stringmap {
private _stringArray:string[] = [];
private _triggerUntilTrueFunctionArray:triggerFunction[] = [];
constructor(){
};
@ -13,6 +19,7 @@ export class Stringmap {
*/
addString(stringArg:string){
this._stringArray.push(stringArg);
this.notifyTrigger();
};
/**
@ -23,20 +30,70 @@ export class Stringmap {
if(this._stringArray[keyArg] == stringArg){
this._stringArray.splice(parseInt(keyArg),1);
};
}
};
this.notifyTrigger();
}
/**
* wipes the Stringmap
*/
wipe(){
this._stringArray = [];
this.notifyTrigger();
}
/**
* check if string is in Stringmap
*/
checkString(stringArg:string):boolean{
checkString(stringArg:string):boolean {
return this._stringArray.indexOf(stringArg) != -1;
}
/**
* checks stringPresence with minimatch
*/
checkMinimatch(stringArg:string){
checkMinimatch(miniMatchStringArg:string):boolean {
let foundMatch:boolean = false;
for(let stringItem of this._stringArray){
if(plugins.minimatch(stringItem,miniMatchStringArg)){
foundMatch = true;
};
};
return foundMatch;
};
/**
* checks if the Stringmap is empty
*/
checkIsEmpty(){
return (this._stringArray.length == 0);
}
// trigger registering
/**
* notifies triggers
*/
private notifyTrigger(){
let filteredArray = this._triggerUntilTrueFunctionArray.filter((functionArg) => {
return !functionArg();
});
this._triggerUntilTrueFunctionArray = filteredArray;
};
/**
* register a new trigger
*/
registerUntilTrue(functionArg:triggerFunction,doFunctionArg){
this._triggerUntilTrueFunctionArray.push(
() => {
let result = functionArg();
if(result == true){
doFunctionArg();
}
return result;
}
);
this.notifyTrigger();
}
}