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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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
213
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
/**
* @module Attribute
*/
define(['abstractList', 'attribute'], function(AbstractList, Attribute) {
return (function() {
/**
* @class
* @classdesc This class represents a list for Attribute.
* @requires Attribute~Attribute
* @extends AbstractList
* @constructs AttributeList
*/
function AttributeList() {
AbstractList.call(this);
this._type = Attribute;
return this;
}
AttributeList.prototype = Object.create(AbstractList.prototype);
AttributeList.prototype.constructor = AttributeList;
/**
* Adds the specified item to the itemList.
*
* @public
* @param {Attribute} attribute AttributeType
* @param {boolean} multipleInstances
*/
AttributeList.prototype.put = function(attribute, multipleInstances) {
multipleInstances = typeof multipleInstances == "undefined" ? false : multipleInstances;
if (attribute instanceof this._type) {
if (multipleInstances || !(this.containsTypeOf(attribute))) {
this._items.push(attribute);
} else {
this.updateValue(attribute);
}
}
};
/**
* Adds all items in the specified list to the
* itemList.
*
* @public
* @param {(AttributeList|Array)} attributeList AttributeList
*/
AttributeList.prototype.putAll = function(attributeList) {
var list = [];
if (attributeList instanceof Array) {
list = attributeList;
} else if (attributeList.constructor === AttributeList) {
list = attributeList.getItems();
}
for ( var i in list) {
this.put(list[i]);
}
};
/**
*
* @deprecated Use containsTypeOf or containsValueOf instead.
* @param {Attribute} attribute
* @param {?Boolean} typeOnly
* @returns {Boolean}
*/
AttributeList.prototype.contains = function(attribute, typeOnly) {
typeOnly = typeof typeOnly == "undefined" ? false : typeOnly;
return typeOnly ? this.containsTypeOf(attribute) : this.containsValueOf(attribute);
};
/**
* Verifies whether an attribute with the type of the given item is included in this list.
*
* @param {Attribute} attribute AttributeType that should be verified.
* @returns {Boolean}
*/
AttributeList.prototype.containsTypeOf = function(attribute) {
if (attribute.constructor === Attribute) {
for (var index in this.getItems()) {
var theAttribute = this.getItems()[index];
if (theAttribute.equalsTypeOf(attribute)) {
return true;
}
}
}
return false;
};
/**
* Verifies whether the given item is included in the list.
*
* @param {Attribute} attribute AttributeValue that should be verified.
* @returns {Boolean}
*/
AttributeList.prototype.containsValueOf = function(attribute) {
if (attribute.constructor === Attribute) {
for (var index in this._items) {
var theAttribute = this._items[index];
if (theAttribute.equalsValueOf(attribute)) {
return true;
}
}
}
return false;
};
/**
*
* @deprecated Use equalsTypesIn or equalsValuesIn instead.
* @param {AttributeList} attributeList
* @param {Boolean} typeOnly
* @returns {Boolean}
*/
AttributeList.prototype.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.
*
* @param {AttributeList} attributeList AttributeList that should be compared.
* @returns {boolean}
*/
AttributeList.prototype.equalsTypesIn = function(attributeList) {
if (attributeList.constructor === AttributeList && attributeList.size() == this.size()) {
for (var index in attributeList.getItems()) {
var theAttribute = attributeList.getItems()[index];
if (!this.containsTypeOf(theAttribute)) return false;
}
return true;
}
return false;
};
/**
* Compare the specified AttributeList with this instance.
*
* @param {AttributeList} attributeList AttributeList that should be compared.
* @returns {boolean}
*/
AttributeList.prototype.equalsValuesIn = function(attributeList) {
if (attributeList.constructor === 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.
*
* @param {(AttributeList|Array)} attributeList Attributes that should be returned.
* @returns {AttributeList}
*/
AttributeList.prototype.getSubset = function(attributeList) {
var response = new AttributeList();
var list = [];
if (attributeList instanceof Array) {
list = attributeList;
} else if (attributeList.constructor === AttributeList) {
list = attributeList.getItems();
}
for (var i in list) {
var theAttribute = list[i];
if (theAttribute.constructor === Attribute) {
var responseAttribute = this.getAttributeWithTypeOf(theAttribute);
if (typeof responseAttribute != "undefined") {
response.put(responseAttribute);
}
}
}
return response;
};
/**
* Returns a subset without the given types.
*
* @param {(AttributeList|Array)} attributeList AttributeTypes that should not be included
* @returns {AttributeList}
*/
AttributeList.prototype.getSubsetWithoutItems = function(attributeList) {
var response = this;
var list = [];
if (attributeList instanceof Array) {
list = attributeList;
} else if (attributeList.constructor === AttributeList) {
list = attributeList.getItems();
}
for (var i in list) {
var attribute = list[i];
if (attribute.constructor === Attribute) {
response.removeAttributeWithTypeOf(attribute);
}
}
return response;
};
/**
* Creates a clone of the current list.
*
* @param {Boolean} typeOnly
* @returns {AttributeList}
*/
AttributeList.prototype.clone = function(typeOnly) {
var newList = new AttributeList();
for (var index in this._items) {
var oldAttribute = this._items[index];
var newAttribute = new Attribute(true)
.withName(oldAttribute.getName())
.withType(oldAttribute.getType())
.withParameters(oldAttribute.getParameters())
.withSynonyms(oldAttribute.getSynonyms());
if (!typeOnly) newAttribute.setValue(oldAttribute.getValue());
newList.put(newAttribute);
}
return newList;
};
/**
*
* @param {Attribute} attribute
* @param {Boolean} allOccurrences
*/
AttributeList.prototype.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);
};
/**
*
* @returns {boolean}
*/
AttributeList.prototype.hasAttributesWithInputParameters = function() {
for (var index in this._items) {
var theAttribute = this._items[index];
if (theAttribute.hasInputParameter()) return true;
}
return false;
};
/**
*
* @returns {AttributeList}
*/
AttributeList.prototype.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.
*
* @param {AttributeType} attribute
* @returns {Attribute}
*/
AttributeList.prototype.getValueForAttributeWithTypeOf = function(attribute) {
return this.getAttributeWithTypeOf(attribute).getValue();
};
/**
*
* @param {Attribute} attribute
* @returns {Attribute}
*/
AttributeList.prototype.getAttributeWithTypeOf = function(attribute) {
for (var index in this.getItems()) {
var theAttribute = this.getItems()[index];
if (theAttribute.equalsTypeOf(attribute)) return theAttribute;
}
};
/**
*
* @param {Attribute} attribute
*/
AttributeList.prototype.updateValue = function(attribute) {
for (var index in this._items) {
var theAttribute = this._items[index];
if (theAttribute.equalsTypeOf(attribute)) this._items[index] = attribute;
}
};
return AttributeList;
})();
});