UNPKG

17.6 kBTypeScriptView Raw
1import { TypeCode } from '../convert/TypeCode';
2import { ICloneable } from './ICloneable';
3import { AnyValue } from './AnyValue';
4import { AnyValueMap } from './AnyValueMap';
5/**
6 * Cross-language implementation of dynamic object array what can hold values of any type.
7 * The stored values can be converted to different types using variety of accessor methods.
8 *
9 * ### Example ###
10 *
11 * let value1 = new AnyValueArray([1, "123.456", "2018-01-01"]);
12 *
13 * value1.getAsBoolean(0); // Result: true
14 * value1.getAsInteger(1); // Result: 123
15 * value1.getAsFloat(1); // Result: 123.456
16 * value1.getAsDateTime(2); // Result: new Date(2018,0,1)
17 *
18 * @see [[StringConverter]]
19 * @see [[TypeConverter]]
20 * @see [[BooleanConverter]]
21 * @see [[IntegerConverter]]
22 * @see [[LongConverter]]
23 * @see [[DoubleConverter]]
24 * @see [[FloatConverter]]
25 * @see [[DateTimeConverter]]
26 * @see [[ICloneable]]
27 */
28export declare class AnyValueArray extends Array<any> implements ICloneable {
29 /**
30 * Creates a new instance of the array and assigns its value.
31 *
32 * @param value (optional) values to initialize this array.
33 */
34 constructor(values?: any[]);
35 /**
36 * Gets an array element specified by its index.
37 *
38 * @param index an index of the element to get.
39 * @returns the value of the array element.
40 */
41 get(index: number): any;
42 /**
43 * Puts a new value into array element specified by its index.
44 *
45 * @param index an index of the element to put.
46 * @param value a new value for array element.
47 */
48 put(index: number, value: any): void;
49 /**
50 * Removes an array element specified by its index
51 *
52 * @param index an index of the element to remove.
53 */
54 remove(index: number): void;
55 /**
56 * Appends new elements to this array.
57 *
58 * @param elements a list of elements to be added.
59 */
60 append(elements: any[]): void;
61 /**
62 * Clears this array by removing all its elements.
63 */
64 clear(): void;
65 /**
66 * Gets the value stored in array element without any conversions.
67 * When element index is not defined it returns the entire array value.
68 *
69 * @param index (optional) an index of the element to get
70 * @returns the element value or value of the array when index is not defined.
71 */
72 getAsObject(index?: number): any;
73 /**
74 * Sets a new value to array element specified by its index.
75 * When the index is not defined, it resets the entire array value.
76 * This method has double purpose because method overrides are not supported in JavaScript.
77 *
78 * @param index (optional) an index of the element to set
79 * @param value a new element or array value.
80 *
81 * @see [[ArrayConverter.toArray]]
82 */
83 setAsObject(index: any, value?: any): void;
84 /**
85 * Converts array element into a string or returns null if conversion is not possible.
86 *
87 * @param index an index of element to get.
88 * @returns string value of the element or null if conversion is not supported.
89 *
90 * @see [[StringConverter.toNullableString]]
91 */
92 getAsNullableString(index: number): string;
93 /**
94 * Converts array element into a string or returns "" if conversion is not possible.
95 *
96 * @param index an index of element to get.
97 * @returns string value ot the element or "" if conversion is not supported.
98 *
99 * @see [[getAsStringWithDefault]]
100 */
101 getAsString(index: number): string;
102 /**
103 * Converts array element into a string or returns default value if conversion is not possible.
104 *
105 * @param index an index of element to get.
106 * @param defaultValue the default value
107 * @returns string value ot the element or default value if conversion is not supported.
108 *
109 * @see [[StringConverter.toStringWithDefault]]
110 */
111 getAsStringWithDefault(index: number, defaultValue: string): string;
112 /**
113 * Converts array element into a boolean or returns null if conversion is not possible.
114 *
115 * @param index an index of element to get.
116 * @returns boolean value of the element or null if conversion is not supported.
117 *
118 * @see [[BooleanConverter.toNullableBoolean]]
119 */
120 getAsNullableBoolean(index: number): boolean;
121 /**
122 * Converts array element into a boolean or returns false if conversion is not possible.
123 *
124 * @param index an index of element to get.
125 * @returns boolean value ot the element or false if conversion is not supported.
126 *
127 * @see [[getAsBooleanWithDefault]]
128 */
129 getAsBoolean(index: number): boolean;
130 /**
131 * Converts array element into a boolean or returns default value if conversion is not possible.
132 *
133 * @param index an index of element to get.
134 * @param defaultValue the default value
135 * @returns boolean value ot the element or default value if conversion is not supported.
136 *
137 * @see [[BooleanConverter.toBooleanWithDefault]]
138 */
139 getAsBooleanWithDefault(index: number, defaultValue: boolean): boolean;
140 /**
141 * Converts array element into an integer or returns null if conversion is not possible.
142 *
143 * @param index an index of element to get.
144 * @returns integer value of the element or null if conversion is not supported.
145 *
146 * @see [[IntegerConverter.toNullableInteger]]
147 */
148 getAsNullableInteger(index: number): number;
149 /**
150 * Converts array element into an integer or returns 0 if conversion is not possible.
151 *
152 * @param index an index of element to get.
153 * @returns integer value ot the element or 0 if conversion is not supported.
154 *
155 * @see [[getAsIntegerWithDefault]]
156 */
157 getAsInteger(index: number): number;
158 /**
159 * Converts array element into an integer or returns default value if conversion is not possible.
160 *
161 * @param index an index of element to get.
162 * @param defaultValue the default value
163 * @returns integer value ot the element or default value if conversion is not supported.
164 *
165 * @see [[IntegerConverter.toIntegerWithDefault]]
166 */
167 getAsIntegerWithDefault(index: number, defaultValue: number): number;
168 /**
169 * Converts array element into a long or returns null if conversion is not possible.
170 *
171 * @param index an index of element to get.
172 * @returns long value of the element or null if conversion is not supported.
173 *
174 * @see [[LongConverter.toNullableLong]]
175 */
176 getAsNullableLong(index: number): number;
177 /**
178 * Converts array element into a long or returns 0 if conversion is not possible.
179 *
180 * @param index an index of element to get.
181 * @returns long value ot the element or 0 if conversion is not supported.
182 *
183 * @see [[getAsLongWithDefault]]
184 */
185 getAsLong(index: number): number;
186 /**
187 * Converts array element into a long or returns default value if conversion is not possible.
188 *
189 * @param index an index of element to get.
190 * @param defaultValue the default value
191 * @returns long value ot the element or default value if conversion is not supported.
192 *
193 * @see [[LongConverter.toLongWithDefault]]
194 */
195 getAsLongWithDefault(index: number, defaultValue: number): number;
196 /**
197 * Converts array element into a float or returns null if conversion is not possible.
198 *
199 * @param index an index of element to get.
200 * @returns float value of the element or null if conversion is not supported.
201 *
202 * @see [[FloatConverter.toNullableFloat]]
203 */
204 getAsNullableFloat(index: number): number;
205 /**
206 * Converts array element into a float or returns 0 if conversion is not possible.
207 *
208 * @param index an index of element to get.
209 * @returns float value ot the element or 0 if conversion is not supported.
210 *
211 * @see [[getAsFloatWithDefault]]
212 */
213 getAsFloat(index: number): number;
214 /**
215 * Converts array element into a float or returns default value if conversion is not possible.
216 *
217 * @param index an index of element to get.
218 * @param defaultValue the default value
219 * @returns float value ot the element or default value if conversion is not supported.
220 *
221 * @see [[FloatConverter.toFloatWithDefault]]
222 */
223 getAsFloatWithDefault(index: number, defaultValue: number): number;
224 /**
225 * Converts array element into a double or returns null if conversion is not possible.
226 *
227 * @param index an index of element to get.
228 * @returns double value of the element or null if conversion is not supported.
229 *
230 * @see [[DoubleConverter.toNullableDouble]]
231 */
232 getAsNullableDouble(index: number): number;
233 /**
234 * Converts array element into a double or returns 0 if conversion is not possible.
235 *
236 * @param index an index of element to get.
237 * @returns double value ot the element or 0 if conversion is not supported.
238 *
239 * @see [[getAsDoubleWithDefault]]
240 */
241 getAsDouble(index: number): number;
242 /**
243 * Converts array element into a double or returns default value if conversion is not possible.
244 *
245 * @param index an index of element to get.
246 * @param defaultValue the default value
247 * @returns double value ot the element or default value if conversion is not supported.
248 *
249 * @see [[DoubleConverter.toDoubleWithDefault]]
250 */
251 getAsDoubleWithDefault(index: number, defaultValue: number): number;
252 /**
253 * Converts array element into a Date or returns null if conversion is not possible.
254 *
255 * @param index an index of element to get.
256 * @returns Date value of the element or null if conversion is not supported.
257 *
258 * @see [[DateTimeConverter.toNullableDateTime]]
259 */
260 getAsNullableDateTime(index: number): Date;
261 /**
262 * Converts array element into a Date or returns the current date if conversion is not possible.
263 *
264 * @param index an index of element to get.
265 * @returns Date value ot the element or the current date if conversion is not supported.
266 *
267 * @see [[getAsDateTimeWithDefault]]
268 */
269 getAsDateTime(index: number): Date;
270 /**
271 * Converts array element into a Date or returns default value if conversion is not possible.
272 *
273 * @param index an index of element to get.
274 * @param defaultValue the default value
275 * @returns Date value ot the element or default value if conversion is not supported.
276 *
277 * @see [[DateTimeConverter.toDateTimeWithDefault]]
278 */
279 getAsDateTimeWithDefault(index: number, defaultValue: Date): Date;
280 /**
281 * Converts array element into a value defined by specied typecode.
282 * If conversion is not possible it returns null.
283 *
284 * @param type the TypeCode that defined the type of the result
285 * @param index an index of element to get.
286 * @returns element value defined by the typecode or null if conversion is not supported.
287 *
288 * @see [[TypeConverter.toNullableType]]
289 */
290 getAsNullableType<T>(type: TypeCode, index: number): T;
291 /**
292 * Converts array element into a value defined by specied typecode.
293 * If conversion is not possible it returns default value for the specified type.
294 *
295 * @param type the TypeCode that defined the type of the result
296 * @param index an index of element to get.
297 * @returns element value defined by the typecode or default if conversion is not supported.
298 *
299 * @see [[getAsTypeWithDefault]]
300 */
301 getAsType<T>(type: TypeCode, index: number): T;
302 /**
303 * Converts array element into a value defined by specied typecode.
304 * If conversion is not possible it returns default value.
305 *
306 * @param type the TypeCode that defined the type of the result
307 * @param index an index of element to get.
308 * @param defaultValue the default value
309 * @returns element value defined by the typecode or default value if conversion is not supported.
310 *
311 * @see [[TypeConverter.toTypeWithDefault]]
312 */
313 getAsTypeWithDefault<T>(type: TypeCode, index: number, defaultValue: T): T;
314 /**
315 * Converts array element into an AnyValue or returns an empty AnyValue if conversion is not possible.
316 *
317 * @param index an index of element to get.
318 * @returns AnyValue value of the element or empty AnyValue if conversion is not supported.
319 *
320 * @see [[AnyValue]]
321 * @see [[AnyValue.constructor]]
322 */
323 getAsValue(index: number): AnyValue;
324 /**
325 * Converts array element into an AnyValueArray or returns null if conversion is not possible.
326 *
327 * @param index an index of element to get.
328 * @returns AnyValueArray value of the element or null if conversion is not supported.
329 *
330 * @see [[fromValue]]
331 */
332 getAsNullableArray(index: number): AnyValueArray;
333 /**
334 * Converts array element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.
335 *
336 * @param index an index of element to get.
337 * @returns AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.
338 *
339 * @see [[fromValue]]
340 */
341 getAsArray(index: number): AnyValueArray;
342 /**
343 * Converts array element into an AnyValueArray or returns default value if conversion is not possible.
344 *
345 * @param index an index of element to get.
346 * @param defaultValue the default value
347 * @returns AnyValueArray value of the element or default value if conversion is not supported.
348 *
349 * @see [[getAsNullableArray]]
350 */
351 getAsArrayWithDefault(index: number, defaultValue: AnyValueArray): AnyValueArray;
352 /**
353 * Converts array element into an AnyValueMap or returns null if conversion is not possible.
354 *
355 * @param index an index of element to get.
356 * @returns AnyValueMap value of the element or null if conversion is not supported.
357 *
358 * @see [[AnyValueMap]]
359 * @see [[AnyValueMap.fromValue]]
360 */
361 getAsNullableMap(index: number): AnyValueMap;
362 /**
363 * Converts array element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.
364 *
365 * @param index an index of element to get.
366 * @returns AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.
367 *
368 * @see [[AnyValueMap]]
369 * @see [[AnyValueMap.fromValue]]
370 */
371 getAsMap(index: number): AnyValueMap;
372 /**
373 * Converts array element into an AnyValueMap or returns default value if conversion is not possible.
374 *
375 * @param index an index of element to get.
376 * @param defaultValue the default value
377 * @returns AnyValueMap value of the element or default value if conversion is not supported.
378 *
379 * @see [[getAsNullableMap]]
380 */
381 getAsMapWithDefault(index: number, defaultValue: AnyValueMap): AnyValueMap;
382 /**
383 * Checks if this array contains a value.
384 * The check uses direct comparison between elements and the specified value.
385 *
386 * @param value a value to be checked
387 * @returns true if this array contains the value or false otherwise.
388 */
389 contains(value: any): boolean;
390 /**
391 * Checks if this array contains a value.
392 * The check before comparison converts elements and the value to type specified by type code.
393 *
394 * @param typeCode a type code that defines a type to convert values before comparison
395 * @param value a value to be checked
396 * @returns true if this array contains the value or false otherwise.
397 *
398 * @see [[TypeConverter.toType]]
399 * @see [[TypeConverter.toNullableType]]
400 */
401 containsAsType<T>(typeCode: TypeCode, value: any): boolean;
402 /**
403 * Creates a binary clone of this object.
404 *
405 * @returns a clone of this object.
406 */
407 clone(): any;
408 /**
409 * Gets a string representation of the object.
410 * The result is a comma-separated list of string representations of individual elements as
411 * "value1,value2,value3"
412 *
413 * @returns a string representation of the object.
414 *
415 * @see [[StringConverter.toString]]
416 */
417 toString(): string;
418 /**
419 * Creates a new AnyValueArray from a list of values
420 *
421 * @param values a list of values to initialize the created AnyValueArray
422 * @returns a newly created AnyValueArray.
423 */
424 static fromValues(...values: any[]): AnyValueArray;
425 /**
426 * Converts specified value into AnyValueArray.
427 *
428 * @param value value to be converted
429 * @returns a newly created AnyValueArray.
430 *
431 * @see [[ArrayConverter.toNullableArray]]
432 */
433 static fromValue(value: any): AnyValueArray;
434 /**
435 * Splits specified string into elements using a separator and assigns
436 * the elements to a newly created AnyValueArray.
437 *
438 * @param values a string value to be split and assigned to AnyValueArray
439 * @param separator a separator to split the string
440 * @param removeDuplicates (optional) true to remove duplicated elements
441 * @returns a newly created AnyValueArray.
442 */
443 static fromString(values: string, separator: string, removeDuplicates?: boolean): AnyValueArray;
444}