1 dojo.provide("calitha.collections.AbstractList");
  2 dojo.require("calitha.collections.IList");
  3 dojo.require("calitha.collections.AbstractCollection");
  4 dojo.require("calitha.exception.UnsupportedOperationException");
  5 dojo.require("calitha.collections.abstractlist.Iterator");
  6 dojo.require("calitha.collections.abstractlist.ListIterator");
  7 dojo.require("calitha.collections.SubList");
  8 
  9 dojo.declare("calitha.collections.AbstractList", [calitha.collections.IList, calitha.collections.AbstractCollection],
 10 /** @lends calitha.collections.AbstractList# */
 11 {
 12     /**
 13      * @constructs
 14      * @extends calitha.collections.IList
 15      * @extends calitha.collections.AbstractCollection
 16      */
 17     constructor: function()
 18     {
 19         this._modCount = 0;
 20     }
 21     ,
 22     add: function(/**Object*/ element)
 23     {
 24         this.insert(this.size(), element);
 25         return true;
 26     }
 27     ,
 28     clear: function()
 29     {
 30         this._removeRange(0, this.size());
 31     }
 32     ,
 33     contains: function(/**Object*/ element)
 34     {
 35 	    return this.indexOf(element) != -1;
 36     }
 37     ,
 38     del: function(/**Number*/ index)
 39     {
 40         throw new calitha.exception.UnsupportedOperationException(Error());
 41     }
 42     ,
 43     equals: function(/**Object*/ obj)
 44     {
 45         if (obj === this)
 46         {
 47             return true;
 48         }
 49         if (!calitha.collections.util.isObjectInstanceOf(obj, calitha.collections.AbstractList))
 50         {
 51             return false;
 52         }
 53 
 54         var it1 = this.listIterator();
 55         var it2 = obj.listIterator();
 56         while(it1.hasNext() && it2.hasNext())
 57         {
 58             var o1 = it1.next();
 59             var o2 = it2.next();
 60             if (!calitha.collections.util.equals(o1, o2))
 61             {
 62                 return false;
 63             }
 64     	}
 65 	    return !(it1.hasNext() || it2.hasNext());
 66     }
 67     ,
 68     hashCode: function()
 69     {
 70         var hashCode = 1;
 71         var it = this.iterator();
 72         while (it.hasNext())
 73         {
 74             var obj = it.next();
 75             hashCode = 31 * hashCode + calitha.collections.util.hashCode(obj);
 76         }
 77         return hashCode;
 78     }
 79     ,
 80     indexOf: function(/**Object*/ element)
 81     {
 82         var it = this.listIterator();
 83         while (it.hasNext())
 84         {
 85             if (calitha.collections.util.equals(it.next(), element))
 86             {
 87                 return it.previousIndex();
 88             }
 89         }
 90         return -1;
 91     }
 92     ,
 93     insert: function(/**Number*/ index, /**Object*/ element)
 94     {
 95         throw new calitha.exception.UnsupportedOperationException(Error());
 96     }
 97     ,
 98     insertAll: function(/**Number*/ index, /**calitha.collections.ICollection*/ collection)
 99     {
100         var modified = false;
101         var it = collection.iterator();
102         while (it.hasNext())
103         {
104             this.insert(index++, it.next());
105             modified = true;
106         }
107         return modified;
108     }
109     ,
110     iterator: function()
111     {
112         return new calitha.collections.abstractlist.Iterator(this);
113     }
114     ,
115     lastIndexOf: function(/**Object*/ element)
116     {
117         var it = this.listIterator(this.size());
118         while (it.hasPrevious())
119         {
120             if (calitha.collections.util.equals(it.previous(), element))
121             {
122                 return it.nextIndex();
123             }
124         }
125         return -1;
126     }
127     ,
128     listIterator: function(/**Number*/ index)
129     {
130         if (index == null)
131         {
132             index = 0;
133         }
134         return new calitha.collections.abstractlist.ListIterator(this, index);
135     }
136     ,
137     set: function(/**Number*/ index, /**Object*/ element)
138     {
139         throw new calitha.exception.UnsupportedOperationException(Error());
140     }
141     ,
142     sort: function(/**calitha.collections.IComparator?*/ comparator)
143     {
144         calitha.collections.sort(this, comparator);
145     }
146     ,
147     subList: function(/**Number*/ fromIndex, /**Number*/ toIndex)
148     {
149         return new calitha.collections.SubList(this, fromIndex, toIndex);
150     }
151     ,
152     _removeRange: function(/**Number*/ fromIndex, /**Number*/ toIndex)
153     {
154         var it = this.listIterator(fromIndex);
155         for (var i = 0, n = toIndex - fromIndex; i < n; i++)
156         {
157             it.next();
158             it.remove();
159         }
160     }
161 });
162 
163 
164