Project

General

Profile

Revision a40b31c1

IDa40b31c162c7cd51c572acb7b062f87f14b3218e
Parent 1210623a
Child bd95f27d

Added by Patrick Plitzner about 2 years ago

ref #7597 Extend compare wrapper to support all statistical measures

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
31 31
import eu.etaxonomy.cdm.model.description.Feature;
32 32
import eu.etaxonomy.cdm.model.description.QuantitativeData;
33 33
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
34
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
34 35
import eu.etaxonomy.cdm.model.description.TextData;
35 36
import eu.etaxonomy.cdm.model.location.NamedArea;
36 37
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
......
304 305

  
305 306
    }
306 307

  
308
    //TODO: this should either be solved in the model class itself
309
    //OR this should cover all possibilities including modifiers for example
307 310
    private class DescriptionElementCompareWrapper {
308 311

  
309 312
        private DescriptionElementBase element;
310 313
        private Set<UUID> stateUuids = new HashSet<>();
311
        private Float min = null;
312
        private Float max = null;
314
        private Set<Float> avgs = new HashSet<>();
315
        private Set<Float> exacts = new HashSet<>();
316
        private Set<Float> maxs = new HashSet<>();
317
        private Set<Float> mins = new HashSet<>();
318
        private Set<Float> sampleSizes = new HashSet<>();
319
        private Set<Float> standardDevs = new HashSet<>();
320
        private Set<Float> lowerBounds = new HashSet<>();
321
        private Set<Float> upperBounds = new HashSet<>();
322
        private Set<Float> variances = new HashSet<>();
313 323

  
314 324
        public DescriptionElementCompareWrapper(DescriptionElementBase element) {
315 325
            this.element = element;
......
319 329
            }
320 330
            else if(element.isInstanceOf(QuantitativeData.class)){
321 331
                QuantitativeData elementData = (QuantitativeData)element;
322
                min = elementData.getMin();
323
                max = elementData.getMax();
324
            }
325
        }
332
                elementData.getStatisticalValues().forEach(value->{
333
                    if(value.getType().equals(StatisticalMeasure.AVERAGE())){
334
                        avgs.add(value.getValue());
335
                    }
336
                    else if(value.getType().equals(StatisticalMeasure.EXACT_VALUE())){
337
                        exacts.add(value.getValue());
338

  
339
                    }
340
                    else if(value.getType().equals(StatisticalMeasure.MAX())){
341
                        maxs.add(value.getValue());
342
                    }
343
                    else if(value.getType().equals(StatisticalMeasure.MIN())){
344
                        mins.add(value.getValue());
345
                    }
346
                    else if(value.getType().equals(StatisticalMeasure.SAMPLE_SIZE())){
347
                        sampleSizes.add(value.getValue());
326 348

  
327
        public DescriptionElementBase unwrap() {
328
            return element;
349
                    }
350
                    else if(value.getType().equals(StatisticalMeasure.STANDARD_DEVIATION())){
351
                        standardDevs.add(value.getValue());
352
                    }
353
                    else if(value.getType().equals(StatisticalMeasure.TYPICAL_LOWER_BOUNDARY())){
354
                        lowerBounds.add(value.getValue());
355

  
356
                    }
357
                    else if(value.getType().equals(StatisticalMeasure.TYPICAL_UPPER_BOUNDARY())){
358
                        upperBounds.add(value.getValue());
359
                    }
360
                    else if(value.getType().equals(StatisticalMeasure.VARIANCE())){
361
                        variances.add(value.getValue());
362
                    }
363
                });
364
            }
329 365
        }
330 366

  
331 367
        @Override
332 368
        public int hashCode() {
333 369
            final int prime = 31;
334 370
            int result = 1;
335
            result = prime * result + ((max == null) ? 0 : max.hashCode());
336
            result = prime * result + ((min == null) ? 0 : min.hashCode());
371
            result = prime * result + getOuterType().hashCode();
372
            result = prime * result + ((avgs == null) ? 0 : avgs.hashCode());
373
            result = prime * result + ((element == null) ? 0 : element.hashCode());
374
            result = prime * result + ((exacts == null) ? 0 : exacts.hashCode());
375
            result = prime * result + ((lowerBounds == null) ? 0 : lowerBounds.hashCode());
376
            result = prime * result + ((maxs == null) ? 0 : maxs.hashCode());
377
            result = prime * result + ((mins == null) ? 0 : mins.hashCode());
378
            result = prime * result + ((sampleSizes == null) ? 0 : sampleSizes.hashCode());
379
            result = prime * result + ((standardDevs == null) ? 0 : standardDevs.hashCode());
337 380
            result = prime * result + ((stateUuids == null) ? 0 : stateUuids.hashCode());
381
            result = prime * result + ((upperBounds == null) ? 0 : upperBounds.hashCode());
382
            result = prime * result + ((variances == null) ? 0 : variances.hashCode());
338 383
            return result;
339 384
        }
340 385

  
......
350 395
                return false;
351 396
            }
352 397
            DescriptionElementCompareWrapper other = (DescriptionElementCompareWrapper) obj;
353
            if (max == null) {
354
                if (other.max != null) {
398
            if (!getOuterType().equals(other.getOuterType())) {
399
                return false;
400
            }
401
            if (avgs == null) {
402
                if (other.avgs != null) {
403
                    return false;
404
                }
405
            } else if (!avgs.equals(other.avgs)) {
406
                return false;
407
            }
408
            if (element == null) {
409
                if (other.element != null) {
410
                    return false;
411
                }
412
            } else if (!element.equals(other.element)) {
413
                return false;
414
            }
415
            if (exacts == null) {
416
                if (other.exacts != null) {
417
                    return false;
418
                }
419
            } else if (!exacts.equals(other.exacts)) {
420
                return false;
421
            }
422
            if (lowerBounds == null) {
423
                if (other.lowerBounds != null) {
424
                    return false;
425
                }
426
            } else if (!lowerBounds.equals(other.lowerBounds)) {
427
                return false;
428
            }
429
            if (maxs == null) {
430
                if (other.maxs != null) {
431
                    return false;
432
                }
433
            } else if (!maxs.equals(other.maxs)) {
434
                return false;
435
            }
436
            if (mins == null) {
437
                if (other.mins != null) {
438
                    return false;
439
                }
440
            } else if (!mins.equals(other.mins)) {
441
                return false;
442
            }
443
            if (sampleSizes == null) {
444
                if (other.sampleSizes != null) {
355 445
                    return false;
356 446
                }
357
            } else if (!max.equals(other.max)) {
447
            } else if (!sampleSizes.equals(other.sampleSizes)) {
358 448
                return false;
359 449
            }
360
            if (min == null) {
361
                if (other.min != null) {
450
            if (standardDevs == null) {
451
                if (other.standardDevs != null) {
362 452
                    return false;
363 453
                }
364
            } else if (!min.equals(other.min)) {
454
            } else if (!standardDevs.equals(other.standardDevs)) {
365 455
                return false;
366 456
            }
367 457
            if (stateUuids == null) {
......
371 461
            } else if (!stateUuids.equals(other.stateUuids)) {
372 462
                return false;
373 463
            }
464
            if (upperBounds == null) {
465
                if (other.upperBounds != null) {
466
                    return false;
467
                }
468
            } else if (!upperBounds.equals(other.upperBounds)) {
469
                return false;
470
            }
471
            if (variances == null) {
472
                if (other.variances != null) {
473
                    return false;
474
                }
475
            } else if (!variances.equals(other.variances)) {
476
                return false;
477
            }
374 478
            return true;
375 479
        }
480

  
481
        private DescriptiveDataSetService getOuterType() {
482
            return DescriptiveDataSetService.this;
483
        }
484

  
376 485
    }
377 486

  
378 487
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)