home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / com / facebook / utils / FacebookArrayCollection.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  3.7 KB  |  147 lines

  1. package com.facebook.utils
  2. {
  3.    import flash.events.EventDispatcher;
  4.    import flash.utils.Dictionary;
  5.    
  6.    public class FacebookArrayCollection extends EventDispatcher
  7.    {
  8.       protected var _source:Array;
  9.       
  10.       protected var hash:Dictionary;
  11.       
  12.       protected var _type:Class;
  13.       
  14.       public function FacebookArrayCollection(param1:Array = null, param2:Class = null)
  15.       {
  16.          super();
  17.          this.reset();
  18.          this._type = param2;
  19.          this.initilizeSource(param1);
  20.       }
  21.       
  22.       protected function verifyIndex(param1:uint) : void
  23.       {
  24.          if(this._source.length < param1)
  25.          {
  26.             throw new RangeError("Index: " + param1 + ", is out of range.");
  27.          }
  28.       }
  29.       
  30.       public function addItem(param1:Object) : void
  31.       {
  32.          this.addItemAt(param1,this.length);
  33.       }
  34.       
  35.       public function get length() : int
  36.       {
  37.          return this._source.length;
  38.       }
  39.       
  40.       public function addItemAt(param1:Object, param2:uint) : void
  41.       {
  42.          if(this.hash[param1] != null)
  43.          {
  44.             throw new Error("Item already exists.");
  45.          }
  46.          if(this._type !== null && !(param1 is this._type))
  47.          {
  48.             throw new TypeError("This collection requires " + this._type + " as the type.");
  49.          }
  50.          this.hash[param1] = true;
  51.          this._source.splice(param2,0,param1);
  52.       }
  53.       
  54.       public function indexOf(param1:Object) : int
  55.       {
  56.          return this._source.indexOf(param1);
  57.       }
  58.       
  59.       public function removeItemAt(param1:uint) : void
  60.       {
  61.          this.verifyIndex(param1);
  62.          var _loc2_:Object = this._source[param1];
  63.          delete this.hash[_loc2_];
  64.          this._source.splice(param1,1);
  65.       }
  66.       
  67.       public function getItemAt(param1:uint) : Object
  68.       {
  69.          this.verifyIndex(param1);
  70.          return this._source[param1];
  71.       }
  72.       
  73.       override public function toString() : String
  74.       {
  75.          return this._source.join(", ");
  76.       }
  77.       
  78.       public function reset() : void
  79.       {
  80.          this.hash = new Dictionary(true);
  81.          this._source = [];
  82.       }
  83.       
  84.       protected function initilizeSource(param1:Array) : void
  85.       {
  86.          this._source = [];
  87.          if(param1 == null)
  88.          {
  89.             return;
  90.          }
  91.          var _loc2_:uint = param1.length;
  92.          var _loc3_:uint = 0;
  93.          while(_loc3_ < _loc2_)
  94.          {
  95.             this.addItem(param1[_loc3_]);
  96.             _loc3_++;
  97.          }
  98.       }
  99.       
  100.       public function findItemByProperty(param1:String, param2:Object, param3:Boolean = false) : Object
  101.       {
  102.          var _loc4_:Object = null;
  103.          for(_loc4_ in this.hash)
  104.          {
  105.             if(param3 && param1 in _loc4_ && _loc4_[param1] === param2)
  106.             {
  107.                return _loc4_;
  108.             }
  109.             if(!param3 && param1 in _loc4_ && _loc4_[param1] == param2)
  110.             {
  111.                return _loc4_;
  112.             }
  113.          }
  114.          return null;
  115.       }
  116.       
  117.       public function get type() : Class
  118.       {
  119.          return this._type;
  120.       }
  121.       
  122.       public function get source() : Array
  123.       {
  124.          return this._source;
  125.       }
  126.       
  127.       public function toArray() : Array
  128.       {
  129.          var _loc1_:Array = [];
  130.          var _loc2_:uint = uint(this.length);
  131.          var _loc3_:uint = 0;
  132.          while(_loc3_ < _loc2_)
  133.          {
  134.             _loc1_.push(this.getItemAt(_loc3_));
  135.             _loc3_++;
  136.          }
  137.          return _loc1_;
  138.       }
  139.       
  140.       public function contains(param1:Object) : Boolean
  141.       {
  142.          return this.hash[param1] === true;
  143.       }
  144.    }
  145. }
  146.  
  147.