2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('arraylist-add', function(Y) {
11 * Collection utilities beyond what is provided in the YUI core
13 * @submodule arraylist-add
17 * Adds methods add and remove to Y.ArrayList
18 * @class ArrayList~add
20 Y.mix(Y.ArrayList.prototype, {
23 * Add a single item to the ArrayList. Does not prevent duplicates.
26 * @param { mixed } item Item presumably of the same type as others in the
28 * @param {Number} index (Optional.) Number representing the position at
29 * which the item should be inserted.
30 * @return {ArrayList} the instance.
33 add: function(item, index) {
34 var items = this._items;
36 if (Y.Lang.isNumber(index)) {
37 items.splice(index, 0, item);
47 * Removes first or all occurrences of an item to the ArrayList. If a
48 * comparator is not provided, uses itemsAreEqual method to determine
52 * @param { mixed } needle Item to find and remove from the list.
53 * @param { Boolean } all If true, remove all occurrences.
54 * @param { Function } comparator optional a/b function to test equivalence.
55 * @return {ArrayList} the instance.
58 remove: function(needle, all, comparator) {
59 comparator = comparator || this.itemsAreEqual;
61 for (var i = this._items.length - 1; i >= 0; --i) {
62 if (comparator.call(this, needle, this.item(i))) {
63 this._items.splice(i, 1);
74 * Default comparator for items stored in this list. Used by remove().
76 * @method itemsAreEqual
77 * @param { mixed } a item to test equivalence with.
78 * @param { mixed } b other item to test equivalance.
79 * @return { Boolean } true if items are deemed equivalent.
81 itemsAreEqual: function(a, b) {
88 }, '3.3.0' ,{requires:['arraylist']});