A Collection Framework class contains all basic classes like Stack, Queue, HashMap, ArrayList, Set
Download Here
define(['require','CONSTANT'], function ( require, CONSTANT ) { /** * A Collection Framework class contains all basic classes like Stack, Queue, HashMap, ArrayList, Set * @name Collections * @class Collections * @example require('Collections') * @exports Collections * @version 1.0 * @module Collections * @augments CONSTANT **/ var Collections = { /** * Object types provided by Collections * @name TYPE * @class TYPE * @example require('Collections').TYPE.STACK * @example require('Collections').TYPE.ARRAYLIST * @example require('Collections').TYPE.HASHMAP * @example require('Collections').TYPE.SET * @example require('Collections').TYPE.QUEUE * @example require('Collections').TYPE.TREE * @exports TYPE * @version 1.0 * @module Collections * @memberOf Collections * @field **/ TYPE:{ /** @constant*/ STACK:"Stack", ARRAYLIST:"ArrayList", HASHMAP:"HashMap", SET:"Set", QUEUE:"Queue", TREE:"Tree" }, /** * A Stack is a Collection that contains duplicate values. Last In First Out. * @name Stack * @class Stack * @example require('Collections').Stack() * @exports Stack * @version 1.0 * @module Collections * @memberOf Collections **/ Stack: function () { var stac = []; var stackObj = { /** * @name pop * @memberOf Collections.Stack * @method * @description removes the top item from teh stacks * @return {Object} item * @function */ pop : function() { return stac.pop(); }, /** * @name push * @memberOf Collections.Stack * @method * @description removes the top item from teh stacks * @param {Object} item * @return {null} * @function */ push : function(item) { stac.push(item); }, /** * @name isEmpty * @memberOf Collections.Stack * @method * @description returns true if teh Stack is empty. * @return {boolean} * @function */ isEmpty : function() { return stac.length == 0; }, /** * @name objType * @memberOf Collections.Stack * @method * @description returns teh Object type as "Stack" * @return {String} ObjectType * @function */ objType : function(){ return "Stack"; }, /** * @name getElements * @memberOf Collections.Queue * @method * @description returns teh Elemnts in the Queue * @return {Object[]} itemArray * @function */ getElements : function(){ return stac.clone(); }, /** * @name toString * @memberOf Collections.Stack * @method * @description returns the JSON data of teh Object * @return {String} ObjectType * @function */ toString : function(){ return "["+stac.join()+"]"; }, /** * @name clone * @memberOf Collections.Stack * @method * @description returns Collection.Stack a new Stack with the cloned object of the items. * @return {Collections.Stack} * @function */ clone:function(){ var Collection = require('Collections'); var cloneStack = Collection.Stack(); var elements = stac; for(var i=0;i=0; i--){ if(elements[i].clone) cloneQueue.add(elements[i].clone()); else cloneQueue.add(elements[i]); } return cloneQueue; } }; return queueObj; }, /** * An ArrayList is a Collection that contains duplicate values. * @name ArrayList * @class ArrayList * @example require('Collections').ArrayList() * @exports ArrayList * @version 1.0 * @module ArrayList * @memberOf Collections **/ ArrayList : function() { var arr = []; var array = { /** * @name add * @memberOf Collections.ArrayList * @method * @description insert an Item to the ArrayList, it adds to the last of the array, It allows duplicate values in the list. * @param {Object} item * @return {null} * @function */ add : function(item) { arr.push(item); }, /** * @name addAll * @memberOf Collections.ArrayList * @method * @description insert an array of Items to the ArrayList, it adds to the last of the array, It allows duplicate values in the list. * @param {Object[]} itemArray * @return {null} * @function */ addAll : function(items) { for(var i=0; i< items.length; i++) this.add(items[i]); }, /** * @name indexOf * @memberOf Collections.ArrayList * @method * @description returns teh index of teh item in the ArrayList, if item not found it returns -1. * @param {Object} item * @return {integer} * @function */ indexOf : function(item) { return arr.indexOf(item); }, /** * @name contains * @memberOf Collections.ArrayList * @method * @description returns whether the item present in the ArrayList. * @param {Object} item * @return {boolean} * @function */ contains:function(item){ return arr.indexOf(item) != -1; }, /** * @name remove * @memberOf Collections.ArrayList * @method * @description remove an item from the array, then the remaining items will be shifted left, and their index will be reduced by 1. * @param {Object} item * @return {null} * @function */ remove : function(item) { if (arr.indexOf(item) >= 0) arr.splice(arr.indexOf(item), 1); }, /** * @name size * @memberOf Collections.ArrayList * @method * @description returns the number of the Elements present in the ArrayList. * @return {integer} * @function */ size:function(){ return arr.length; }, /** * @name get * @memberOf Collections.ArrayList * @method * @description returns the object at the prvided index. * @param {integer} index * @return {Object} item * @function */ get : function(index){ return arr[index]; }, /** * @name set * @memberOf Collections.ArrayList * @method * @description set an item at the specified location * @param {integer} index * @param {Object} Item * @return {null} * @function */ set:function(index, item){ if(index<0) throw "Index out of bound exception"; arr[index]=item; }, /** * @name getElements * @memberOf Collections.ArrayList * @method * @description returns teh Elemnts in the ArrayList * @return {Object[]} itemArray * @function */ getElements : function(){ return arr.clone(); }, /** * @name objType * @memberOf Collections.ArrayList * @method * @description returns teh Object type as "ArrayList" * @return {String} ObjectType * @function */ objType:function(){ return "ArrayList"; }, /** * @name toString * @memberOf Collections.ArrayList * @method * @description returns the JSON data of teh Object * @return {String} ObjectType * @function */ toString : function(){ return "["+arr.join()+"]"; }, /** * @name json * @memberOf Collections.ArrayList * @method * @description returns the JSON string * @return {String} json * @function */ json :function(){ var jsonArr=[]; for(var i=0; i