module wdCb { export class Stack extends List{ public static create(children = []){ var obj = new this(>children); return obj; } constructor(children:Array = []){ super(); this.children = children; } get top(){ return this.children[this.children.length - 1]; } public push(element:T){ this.children.push(element); } public pop(){ return this.children.pop(); } public clear(){ this.removeAllChildren(); } public clone(); public clone(isDeep: boolean); public clone(target: Stack); public clone(target: Stack, isDeep: boolean); public clone(...args) { var target: Stack = null, isDeep: boolean = null; if (args.length === 0) { isDeep = false; target = Stack.create(); } else if (args.length === 1) { if (JudgeUtils.isBoolean(args[0])) { target = Stack.create(); isDeep = args[0]; } else { target = args[0]; isDeep = false; } } else { target = args[0]; isDeep = args[1]; } if (isDeep === true) { target.setChildren(ExtendUtils.extendDeep(this.children)); } else { target.setChildren(ExtendUtils.extend([], this.children)); } return target; } public filter(func:(value:T, index:number) => boolean):Collection { var children = this.children, result = [], value = null; for(let i = 0, len = children.length; i < len; i++){ value = children[i]; if (func.call(children, value, i)) { result.push(value); } } return Collection.create(result); } public findOne(func:(value:T, index:number) => boolean){ var scope = this.children, result:T = null; this.forEach((value:T, index) => { if (!func.call(scope, value, index)) { return; } result = value; return $BREAK; }); return result; } public reverse () { return Collection.create(this.copyChildren().reverse()); } public removeChild(arg:any){ return Collection.create(this.removeChildHelper(arg)); } public sort(func:(a:T, b:T) => any, isSortSelf = false):Collection{ if(isSortSelf){ this.children.sort(func); return this; } return Collection.create(this.copyChildren().sort(func)); } public map(func:(value:T, index:number) => any){ var resultArr = []; this.forEach((e, index) => { var result = func(e, index); if(result !== $REMOVE){ resultArr.push(result); } //e && e[handlerName] && e[handlerName].apply(context || e, valueArr); }); return Collection.create(resultArr); } public removeRepeatItems(){ var noRepeatList = Collection.create(); this.forEach((item:T) => { if (noRepeatList.hasChild(item)) { return; } noRepeatList.addChild(item); }); return noRepeatList; } public hasRepeatItems(){ var noRepeatList = Collection.create(), hasRepeat:boolean = false; this.forEach((item:T) => { if (noRepeatList.hasChild(item)) { hasRepeat = true; return $BREAK; } noRepeatList.addChild(item); }); return hasRepeat; } } }