/**
* This module represents an AttributeTypeList. It is a subclass of AbstractList.
*
* @module AttributeTypeList
* @fileOverview
*/
define([ 'easejs', 'abstractList', 'attributeType' ],
function(easejs, AbstractList, AttributeType) {
var Class = easejs.Class;
/**
* @class AttributeTypeList
* @classdesc This class represents a list for AttributeType.
* @extends AbstractList
* @requires easejs
* @requires AbstractList
* @requires AttributeType
*/
var AttributeTypeList = Class('AttributeTypeList').extend(AbstractList, {
/**
* @alias counter
* @protected
* @type {integer}
* @memberof AttributeTypeList#
* @desc Number of items.
*/
'protected counter' : 0,
/**
* @alias items
* @protected
* @type {AttributeTypeList}
* @memberof AttributeTypeList#
* @desc ItemList
*/
'protected items' : [],
/**
* Builder for item list.
*
* @public
* @alias withItems
* @memberof AttributeTypeList#
* @param {(AttributeTypeList|Array)}
* _attributeTypeList AttributeTypeList
* @returns {AttributeTypeList}
*/
'public withItems' : function(
_attributeTypeList) {
var list = new Array();
if (_attributeTypeList instanceof Array) {
list = _attributeTypeList;
} else if (Class.isA(AttributeTypeList, _attributeTypeList)) {
list = _attributeTypeList.getItems();
}
for ( var i in list) {
var attributeType = list[i];
if (Class.isA(AttributeType, attributeType)) {
this.items[attributeType.getName()] = attributeType;
this.counter++;
}
}
return this;
},
/**
* Adds the specified item to the itemList.
*
* @public
* @alias put
* @memberof AttributeTypeList#
* @param {AttributeType}
* _attributeType AttributeType
*/
'public put' : function(_attributeType) {
if (Class.isA(AttributeType, _attributeType)) {
if (!(this.containsKey(_attributeType.getName()))) {
this.counter++;
}
this.items[_attributeType.getName()] = _attributeType;
}
},
/**
* Adds all items in the specified list to the
* itemList.
*
* @public
* @alias putAll
* @memberof AttributeTypeList#
* @param {(AttributeTypeList|Array)}
* _attributeTypeList AttributeTypeList
*/
'public putAll' : function(_attributeTypeList) {
var list = new Array();
if (_attributeTypeList instanceof Array) {
list = _attributeTypeList;
} else if (Class.isA(AttributeTypeList, _attributeTypeList)) {
list = _attributeTypeList.getItems();
}
for ( var i in list) {
var attributeType = list[i];
if (Class.isA(AttributeType, attributeType)) {
if (!(this.containsKey(attributeType.getName()))) {
this.counter++;
}
this.items[attributeType.getName()] = attributeType;
}
}
},
/**
* Verifies whether the given item is included
* in this list.
*
* @public
* @alias contains
* @memberof AttributeTypeList#
* @param {AttributeType}
* _item AttributeType that should be
* verified.
* @returns {boolean}
*/
'public contains' : function(_item) {
if (Class.isA(AttributeType, _item)) {
var tmp = this.getItem(_item.getName());
if (!(typeof tmp === 'undefined')
&& tmp.equals(_item)) {
return true;
}
}
return false;
},
/**
* Compare the specified AttributeTypeList with this instance.
*
* @public
* @alias equals
* @memberof AttributeTypeList#
* @param {AttributeTypeList} _list AttributeTypeList that should be compared.
* @returns {boolean}
*/
'public equals' : function(_list) {
if (Class.isA(AttributeTypeList, _list) && _list.size() == this.size()) {
var items = _list.getItems();
for ( var i in items) {
var item = items[i];
if (!this.contains(item)) {
return false;
}
}
return true;
}
return false;
},
});
return AttributeTypeList;
});