Project

General

Profile

« Previous | Next » 

Revision e0812cf2

Added by Patrick Plitzner over 5 years ago

ref #7674 Enhance sorting of matrix rows

  • aggregated taxon description always on top
  • specimen descriptions based on id

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/MatrixRowComparator.java
11 11
import java.util.Comparator;
12 12

  
13 13
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
14
import eu.etaxonomy.cdm.model.common.MarkerType;
15
import eu.etaxonomy.cdm.model.description.DescriptionBase;
16
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
17
import eu.etaxonomy.cdm.model.description.TaxonDescription;
14 18
import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
15 19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
16 20
import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator;
......
47 51
            TaxonNode node1 = rowWrapper1.getTaxonNode().getParent();
48 52
            TaxonNode node2 = rowWrapper2.getTaxonNode().getParent();
49 53
            if(node1!=null && node2!=null){
50
                return comparator.compare(node1, node2);
54
                //compare by taxon node
55
                int compare = comparator.compare(node1, node2);
56
                if(compare!=0){
57
                    return compare;
58
                }
59
                DescriptionBase description1 = rowWrapper1.getDescription();
60
                DescriptionBase description2 = rowWrapper2.getDescription();
61
                //compare by taxon description type
62
                if(description1 instanceof TaxonDescription){
63
                    if(description2 instanceof SpecimenDescription){
64
                        return -1;
65
                    }
66
                }
67
                else{
68
                    if(description2 instanceof TaxonDescription){
69
                        return 1;
70
                    }
71
                }
72
                //both descriptions are of the same type
73
                if(description1 instanceof SpecimenDescription){
74
                    //description2 has to also be a SpecimenDescription
75
                    SpecimenDescription specimenDescription1 = (SpecimenDescription)description1;
76
                    SpecimenDescription specimenDescription2 = (SpecimenDescription)description2;
77
                    int id1 = specimenDescription1.getDescribedSpecimenOrObservation().getId();
78
                    int id2 = specimenDescription2.getDescribedSpecimenOrObservation().getId();
79
                    return id1-id2;
80
                }
81
                else if(description1 instanceof TaxonDescription){
82
                    //description2 has to also be a TaxonDescription
83
                    TaxonDescription taxonDescription1 = (TaxonDescription)description1;
84
                    TaxonDescription taxonDescription2 = (TaxonDescription)description2;
85
                    boolean isComputed1 = taxonDescription1.getMarkers().stream()
86
                            .anyMatch(marker -> marker.getMarkerType().equals(MarkerType.COMPUTED()));
87
                    boolean isComputed2 = taxonDescription2.getMarkers().stream()
88
                            .anyMatch(marker -> marker.getMarkerType().equals(MarkerType.COMPUTED()));
89
                    if(isComputed1){
90
                        if(!isComputed2){
91
                            return -1;
92
                        }
93
                    }
94
                    if(isComputed2){
95
                        return 1;
96
                    }
97
                    //TODO: implement compare for different description types
98
                }
51 99
            }
52 100
        }
53 101
        return o1.hashCode()-o2.hashCode();

Also available in: Unified diff