Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* This module represents an AttributeList. It is a subclass of AbstractList.
*
* @module AttributeList
* @fileOverview
*/
define(['easejs', 'abstractList', 'attribute', 'parameterList' ],
function(easejs, AbstractList, Attribute, ParameterList) {
var Class = easejs.Class;
/**
* @class AttributeList
* @classdesc This class represents a list for Attribute.
* @extends AbstractList
* @requires easejs
* @requires AbstractList
* @requires Attribute
*/
var AttributeList = Class('AttributeList').extend(AbstractList, {
/**
* @alias items
* @protected
* @type {Array.<Attribute>}
* @memberof AttributeList#
* @desc ItemList
*/
'protected items' : [],
/**
* Builder for item list.
*
* @public
* @alias withItems
* @memberof AttributeList#
* @param {(AttributeList)} _attributeList AttributeList
* @returns {AttributeList}
*/
'public withItems' : function(_attributeList) {
var list = [];
if (_attributeList instanceof Array) {
list = _attributeList;
} else if (Class.isA(AttributeList, _attributeList)) {
list = _attributeList.getItems();
}
this.items = list;
return this;
},
/**
* Adds the specified item to the itemList.
*
* @public
* @alias put
* @memberof AttributeList#
* @param {AttributeType} _attribute AttributeType
* @param {boolean} _multipleInstances
*/
'public put' : function(_attribute, _multipleInstances) {
_multipleInstances = typeof _multipleInstances == "undefined" ? false : _multipleInstances;
if (Class.isA(Attribute, _attribute)) {
if (_multipleInstances || !(this.containsTypeOf(_attribute))) {
this.items.push(_attribute);
} else {
this.updateValue(_attribute);
}
}
},
/**
* Adds all items in the specified list to the
* itemList.
*
* @public
* @alias putAll
* @memberof AttributeList#
* @param {(AttributeList|Array)} _attributeList AttributeList
*/
'public putAll' : function(_attributeList) {
var list = [];
if (_attributeList instanceof Array) {
list = _attributeList;
} else if (Class.isA(AttributeList, _attributeList)) {
list = _attributeList.getItems();
}
for ( var i in list) {
this.put(list[i]);
}
},
/**
*
* @param {Attribute} _attribute
* @param {?boolean} _typeOnly
* @returns {*}
*/
'public contains': function(_attribute, _typeOnly) {
_typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly;
return _typeOnly ? this.containsTypeOf(_attribute) : this.containsValueOf(_attribute);
},
/**
* Verifies whether the given item is included
* in this list.
*
* @public
* @alias containsTypeOf
* @memberof AttributeList#
* @param {AttributeType} _attribute AttributeType that should be verified.
* @returns {boolean}
*/
'public containsTypeOf' : function(_attribute) {
if (Class.isA(Attribute, _attribute)) {
for (var index in this.items) {
var tmp = this.items[index];
if (tmp.equalsTypeOf(_attribute)) {
return true;
}
}
}
return false;
},
/**
* Verifies whether the given item is included
* in the list.
*
* @public
* @alias containsValueOf
* @memberof AttributeList#
* @param {Attribute} _attribute AttributeValue that should be verified.
* @returns {boolean}
*/
'public containsValueOf' : function(_attribute) {
if (Class.isA(Attribute, _attribute)) {
for (var index in this.items) {
var tmp = this.items[index];
if (tmp.equalsValueOf(_attribute)) {
return true;
}
}
}
return false;
},
'public equals': function(_attributeList, _typeOnly) {
_typeOnly = typeof _typeOnly == "undefined" ? false : _typeOnly;
return _typeOnly ? this.equalsTypesIn(_attributeList) : this.equalsValuesIn(_attributeList);
},
/**
* Compare the specified AttributeList with this instance.
*
* @public
* @alias equalsTypesIn
* @memberof AttributeList#
* @param {AttributeList} _attributeList AttributeList that should be compared.
* @returns {boolean}
*/
'public equalsTypesIn' : function(_attributeList) {
if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) {
for (var index in _attributeList.getItems()) {
var theAttributeType = _attributeList.getItems()[index];
if (!this.containsTypeOf(theAttributeType)) return false;
}
return true;
}
return false;
},
/**
* Compare the specified AttributeList with
* this instance.
*
* @public
* @alias equalsValuesIn
* @memberof AttributeList#
* @param {AttributeList} _attributeList AttributeList that should be compared.
* @returns {boolean}
*/
'public equalsValuesIn' : function(_attributeList) {
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
if (Class.isA(AttributeList, _attributeList) && _attributeList.size() == this.size()) {
for (var index in _attributeList.getItems()) {
var theAttribute = _attributeList.getItems()[index];
if (!this.containsValueOf(theAttribute)) return false;
}
return true;
}
return false;
},
/**
* Returns only this values that matches to the
* given type.
*
* @public
* @alias getSubset
* @memberof AttributeList#
* @param {(AttributeList|Array)} _attributeList Attributes that should be returned.
* @returns {AttributeList}
*/
'public getSubset' : function(_attributeList) {
var response = new AttributeList();
var list = [];
if (_attributeList instanceof Array) {
list = _attributeList;
} else if (Class.isA(AttributeList, _attributeList)) {
list = _attributeList.getItems();
}
for (var i in list) {
var attribute = list[i];
if (Class.isA(Attribute, attribute)) {
var attribute = this.getAttributeWithTypeOf(attribute);
if (typeof attribute != "NO_VALUE") {
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
response.put(attribute);
}
}
}
return response;
},
/**
* Returns a subset without the given types.
*
* @public
* @alias getSubsetWithoutItems
* @memberof AttributeList#
* @param {(AttributeList|Array)} _attributeList AttributeTypes that should not be included
* @returns {AttributeList}
*/
'public getSubsetWithoutItems' : function(_attributeList) {
var response = this;
var list = [];
if (_attributeList instanceof Array) {
list = _attributeList;
} else if (Class.isA(AttributeList, _attributeList)) {
list = _attributeList.getItems();
}
for (var i in list) {
var attribute = list[i];
if (Class.isA(Attribute, attribute)) {
response.removeAttributeWithTypeOf(attribute);
}
}
return response;
},
/**
* Creates a clone of the current list.
*
* @public
* @alias clone
* @memberof AttributeList#
* @returns {AttributeList}
*/
'public clone': function(_typeOnly) {
var newList = new AttributeList();
for (var index in this.items) {
var oldAttribute = this.items[index];
var newAttribute = new Attribute().withName(oldAttribute.getName()).withType(oldAttribute.getType()).withParameters(oldAttribute.getParameters());
if (!_typeOnly) newAttribute.setValue(oldAttribute.getValue());
newList.put(newAttribute);
}
return newList;
},
'public removeAttributeWithTypeOf': function(_attribute, _allOccurrences) {
_allOccurrences = typeof _allOccurrences == "undefined" ? false : _allOccurrences;
for (var index in this.items) {
var theAttribute = this.items[index];
if (theAttribute.equalsTypeOf(_attribute)) {
this.items.splice(index, 1);
}
}
if (_allOccurrences && this.contains(_attribute)) this.removeAttributeWithTypeOf(_attribute, _allOccurrences);
},
'public hasAttributesWithInputParameters': function() {
for (var index in this.items) {
var theAttribute = this.items[index];
if (theAttribute.hasInputParameter()) return true;
}
return false;
},
'public getAttributesWithInputParameters': function() {
var list = new AttributeList();
for (var index in this.items) {
var theAttribute = this.items[index];
if (theAttribute.hasInputParameter()) list.put(theAttribute);
}
return list;
},
/**
* Returns the attribute value that matches the provided attribute type.
*
* @public
* @alias getValueForAttributeWithTypeOf
* @memberof AttributeList#
* @param {AttributeType} _attribute
* @returns {Attribute}
*/
'public getValueForAttributeWithTypeOf': function(_attribute) {
return this.getAttributeWithTypeOf(_attribute).getValue();
},
'public getAttributeWithTypeOf': function(_attribute) {
for (var index in this.getItems()) {
var theAttribute = this.getItems()[index];
if (theAttribute.equalsTypeOf(_attribute)) return theAttribute;
}
},
'public updateValue': function(_attribute) {
for (var index in this.items) {
var theAttribute = this.items[index];
if (theAttribute.equalsTypeOf(_attribute)) this.items[index] = _attribute;
}
}
});
return AttributeList;
});