3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('arraylist-add', function(Y) {
10 * Collection utilities beyond what is provided in the YUI core
12 * @submodule arraylist-add
13 * @deprecated Use ModelList or a custom ArrayList subclass
17 * Adds methods add and remove to Y.ArrayList
19 Y.mix(Y.ArrayList.prototype, {
22 * Add a single item to the ArrayList. Does not prevent duplicates.
25 * @param { mixed } item Item presumably of the same type as others in the
27 * @param {Number} index (Optional.) Number representing the position at
28 * which the item should be inserted.
29 * @return {ArrayList} the instance.
31 * @deprecated Use ModelList or a custom ArrayList subclass
34 add: function(item, index) {
35 var items = this._items;
37 if (Y.Lang.isNumber(index)) {
38 items.splice(index, 0, item);
48 * Removes first or all occurrences of an item to the ArrayList. If a
49 * comparator is not provided, uses itemsAreEqual method to determine
53 * @param { mixed } needle Item to find and remove from the list.
54 * @param { Boolean } all If true, remove all occurrences.
55 * @param { Function } comparator optional a/b function to test equivalence.
56 * @return {ArrayList} the instance.
58 * @deprecated Use ModelList or a custom ArrayList subclass
61 remove: function(needle, all, comparator) {
62 comparator = comparator || this.itemsAreEqual;
64 for (var i = this._items.length - 1; i >= 0; --i) {
65 if (comparator.call(this, needle, this.item(i))) {
66 this._items.splice(i, 1);
77 * Default comparator for items stored in this list. Used by remove().
79 * @method itemsAreEqual
80 * @param { mixed } a item to test equivalence with.
81 * @param { mixed } b other item to test equivalance.
82 * @return { Boolean } true if items are deemed equivalent.
84 * @deprecated Use ModelList or a custom ArrayList subclass
86 itemsAreEqual: function(a, b) {
93 }, '3.5.0' ,{requires:['arraylist']});