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 package com.rapiddweller.model.data;
28
29 import com.rapiddweller.common.operation.AndOperation;
30 import com.rapiddweller.common.operation.MaxNumberStringOperation;
31 import com.rapiddweller.common.operation.MaxOperation;
32 import com.rapiddweller.common.operation.MinNumberStringOperation;
33 import com.rapiddweller.common.operation.MinOperation;
34 import com.rapiddweller.script.PrimitiveType;
35
36
37
38
39
40
41
42
43
44 public class SimpleTypeDescriptor extends TypeDescriptor {
45
46
47
48
49 public static final String MIN = "min";
50
51
52
53 public static final String MAX = "max";
54
55
56
57 public static final String MIN_INCLUSIVE = "minInclusive";
58
59
60
61 public static final String MAX_INCLUSIVE = "maxInclusive";
62
63
64
65
66 public static final String GRANULARITY = "granularity";
67
68
69
70
71 public static final String TRUE_QUOTA = "trueQuota";
72
73
74
75 public static final String MIN_LENGTH = "minLength";
76
77
78
79 public static final String MAX_LENGTH = "maxLength";
80
81
82
83 public static final String LENGTH_DISTRIBUTION = "lengthDistribution";
84
85
86
87
88 public static final String CONSTANT = "constant";
89
90
91
92 public static final String VALUES = "values";
93
94
95
96 public static final String MAP = "map";
97
98 private PrimitiveType primitiveType = null;
99
100
101
102
103
104
105
106 public SimpleTypeDescriptor(String name, DescriptorProvider provider) {
107 this(name, provider, (String) null);
108 }
109
110
111
112
113
114
115
116
117 public SimpleTypeDescriptor(String name, DescriptorProvider provider,
118 SimpleTypeDescriptor parent) {
119 this(name, provider, parent.getName());
120 this.parent = parent;
121 }
122
123
124
125
126
127
128
129
130 public SimpleTypeDescriptor(String name, DescriptorProvider provider,
131 String parentName) {
132 super(name, provider, parentName);
133
134 addConstraint(MIN, String.class, new MaxNumberStringOperation());
135 addConstraint(MAX, String.class, new MinNumberStringOperation());
136 addConstraint(MIN_INCLUSIVE, Boolean.class, new AndOperation());
137 addConstraint(MAX_INCLUSIVE, Boolean.class, new AndOperation());
138 addConfig(GRANULARITY, String.class);
139
140 addConfig(TRUE_QUOTA, Double.class);
141
142 addConstraint(MIN_LENGTH, Integer.class, new MaxOperation<>());
143 addConstraint(MAX_LENGTH, Integer.class, new MinOperation<>());
144 addConfig(LENGTH_DISTRIBUTION, String.class);
145
146 addConfig(VALUES, String.class);
147 addConfig(CONSTANT, String.class);
148 addConfig(MAP, String.class);
149 }
150
151
152
153 @Override
154 public SimpleTypeDescriptor getParent() {
155 return (SimpleTypeDescriptor) super.getParent();
156 }
157
158
159
160
161
162
163 public PrimitiveType getPrimitiveType() {
164 if (primitiveType != null) {
165 return primitiveType;
166 }
167 primitiveType = PrimitiveType.getInstance(getName());
168 if (primitiveType != null) {
169 return primitiveType;
170 }
171 if (getParent() != null) {
172 return getParent().getPrimitiveType();
173 }
174 return null;
175 }
176
177
178
179
180
181
182 public String getMin() {
183 return (String) getDetailValue(MIN);
184 }
185
186
187
188
189
190
191 public void setMin(String min) {
192 setDetailValue(MIN, min);
193 }
194
195
196
197
198
199
200 public Boolean isMinInclusive() {
201 return (Boolean) getDetailValue(MIN_INCLUSIVE);
202 }
203
204
205
206
207
208
209 public void setMinInclusive(Boolean minInclusive) {
210 setDetailValue(MIN, minInclusive);
211 }
212
213
214
215
216
217
218 public String getMax() {
219 return (String) getDetailValue(MAX);
220 }
221
222
223
224
225
226
227 public void setMax(String max) {
228 setDetailValue(MAX, max);
229 }
230
231
232
233
234
235
236 public Boolean isMaxInclusive() {
237 return (Boolean) getDetailValue(MAX_INCLUSIVE);
238 }
239
240
241
242
243
244
245 public void setMaxInclusive(Boolean maxInclusive) {
246 setDetailValue(MAX_INCLUSIVE, maxInclusive);
247 }
248
249
250
251
252
253
254 public String getGranularity() {
255 return (String) getDetailValue(GRANULARITY);
256 }
257
258
259
260
261
262
263 public void setGranularity(String granularity) {
264 setDetailValue(GRANULARITY, granularity);
265 }
266
267
268
269
270
271
272 public Double getTrueQuota() {
273 return (Double) getDetailValue(TRUE_QUOTA);
274 }
275
276
277
278
279
280
281 public void setTrueQuota(Double trueQuota) {
282 setDetailValue(TRUE_QUOTA, trueQuota);
283 }
284
285
286
287
288
289
290 public Integer getMinLength() {
291 return (Integer) getDetailValue(MIN_LENGTH);
292 }
293
294
295
296
297
298
299 public void setMinLength(Integer minLength) {
300 setDetailValue(MIN_LENGTH, minLength);
301 }
302
303
304
305
306
307
308 public Integer getMaxLength() {
309 return (Integer) getDetailValue(MAX_LENGTH);
310 }
311
312
313
314
315
316
317 public void setMaxLength(Integer maxLength) {
318 setDetailValue(MAX_LENGTH, maxLength);
319 }
320
321
322
323
324
325
326 public String getLengthDistribution() {
327 return (String) getDetailValue(LENGTH_DISTRIBUTION);
328 }
329
330
331
332
333
334
335 public void setLengthDistribution(String lengthDistribution) {
336 setDetailValue(LENGTH_DISTRIBUTION, lengthDistribution);
337 }
338
339
340
341
342
343
344 public String getValues() {
345 return (String) getDetailValue(VALUES);
346 }
347
348
349
350
351
352
353 public void setValues(String values) {
354 setDetailValue(VALUES, values);
355 }
356
357
358
359
360
361
362 public void addValue(String value) {
363 String valuesBefore = getValues();
364 if (valuesBefore == null || valuesBefore.length() == 0) {
365 setValues(value);
366 } else {
367 setValues(valuesBefore + ',' + value);
368 }
369 }
370
371
372
373
374
375
376 public String getConstant() {
377 return (String) getDetailValue(CONSTANT);
378 }
379
380
381
382
383
384
385 public void setConstant(String constant) {
386 setDetailValue(CONSTANT, constant);
387 }
388
389
390
391
392
393
394 public String getMap() {
395 return (String) getDetailValue(MAP);
396 }
397
398
399
400
401
402
403 public void setMap(String map) {
404 setDetailValue(MAP, map);
405 }
406
407
408
409
410
411
412
413
414
415 public SimpleTypeDescriptor withMin(String min) {
416 setMin(min);
417 return this;
418 }
419
420
421
422
423
424
425
426 public SimpleTypeDescriptor withMax(String max) {
427 setMax(max);
428 return this;
429 }
430
431
432
433
434
435
436
437 public SimpleTypeDescriptor withGranularity(String granularity) {
438 setGranularity(granularity);
439 return this;
440 }
441
442
443
444
445
446
447
448 public SimpleTypeDescriptor withPattern(String pattern) {
449 setPattern(pattern);
450 return this;
451 }
452
453
454
455
456
457
458
459 public SimpleTypeDescriptor withDistribution(String distribution) {
460 setDistribution(distribution);
461 return this;
462 }
463
464
465
466
467
468
469
470 public SimpleTypeDescriptor withDataset(String dataset) {
471 setDataset(dataset);
472 return this;
473 }
474
475
476
477
478
479
480
481 public SimpleTypeDescriptor withLocaleId(String localeId) {
482 setLocaleId(localeId);
483 return this;
484 }
485
486
487
488
489
490
491
492 public SimpleTypeDescriptor withTrueQuota(Double trueQuota) {
493 setTrueQuota(trueQuota);
494 return this;
495 }
496
497
498
499
500
501
502
503 public SimpleTypeDescriptor withUri(String source) {
504 setSource(source);
505 return this;
506 }
507
508
509
510
511
512
513
514 public SimpleTypeDescriptor withValues(String values) {
515 this.setValues(values);
516 return this;
517 }
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554 }