Project

General

Profile

« Previous | Next » 

Revision 1ddf0695

Added by Andreas Müller almost 2 years ago

cleanup

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/name/TypeDesignationSetManager.java
76 76

  
77 77
    private TaxonName typifiedName;
78 78

  
79
    private Comparator<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entryComparator = new Comparator<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>>(){
80

  
81
        /**
82
          * Sorts the base entities (TypedEntityReference) in the following order:
83
          *
84
          * 1. FieldUnits
85
          * 2. DerivedUnit (in case of missing FieldUnit we expect the base type to be DerivedUnit)
86
          * 3. NameType
87
          *
88
          * {@inheritDoc}
89
          */
90
         @Override
91
         public int compare(Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> o1, Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> o2) {
92

  
93
             TypeDesignationWorkingSet ws1 = o1.getValue();
94
             TypeDesignationWorkingSet ws2 = o2.getValue();
95

  
96
             if (ws1.getWorkingsetType() != ws2.getWorkingsetType()){
97
                 //first specimen types, then name types (very rare case anyway)
98
                 return ws1.getWorkingsetType() == TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET? 1:-1;
99
             }
79
    private Class tdType1;
100 80

  
101
             boolean hasStatus1 = !ws1.keySet().contains(null) && !ws1.keySet().contains(NullTypeDesignationStatus.SINGLETON());
102
             boolean hasStatus2 = !ws2.keySet().contains(null) && !ws2.keySet().contains(NullTypeDesignationStatus.SINGLETON());
103
             if (hasStatus1 != hasStatus2){
104
                 //first without status as it is difficult to distinguish a non status from a "same" status record if the first record has a status and second has no status
105
                 return hasStatus1? 1:-1;
106
             }
81
    /**
82
     * Sorts the base entities (TypedEntityReference) in the following order:
83
     *
84
     * 1. FieldUnits
85
     * 2. DerivedUnit (in case of missing FieldUnit we expect the base type to be DerivedUnit)
86
     * 3. NameType
87
     *
88
     * {@inheritDoc}
89
     */
90
    private Comparator<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entryComparator = (o1,o2)->{
91

  
92
         TypeDesignationWorkingSet ws1 = o1.getValue();
93
         TypeDesignationWorkingSet ws2 = o2.getValue();
94

  
95
         if (ws1.getWorkingsetType() != ws2.getWorkingsetType()){
96
             //first specimen types, then name types (very rare case anyway)
97
             return ws1.getWorkingsetType() == TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET? 1:-1;
98
         }
99

  
100
         boolean hasStatus1 = !ws1.keySet().contains(null) && !ws1.keySet().contains(NullTypeDesignationStatus.SINGLETON());
101
         boolean hasStatus2 = !ws2.keySet().contains(null) && !ws2.keySet().contains(NullTypeDesignationStatus.SINGLETON());
102
         if (hasStatus1 != hasStatus2){
103
             //first without status as it is difficult to distinguish a non status from a "same" status record if the first record has a status and second has no status
104
             return hasStatus1? 1:-1;
105
         }
107 106

  
108
             //                boolean hasStatus1 = ws1.getTypeDesignations(); //.stream().filter(td -> td.getSt);
107
         //boolean hasStatus1 = ws1.getTypeDesignations(); //.stream().filter(td -> td.getSt);
109 108

  
110
             Class<?> type1 = o1.getKey().getType();
111
             Class<?> type2 = o2.getKey().getType();
109
         Class<?> type1 = o1.getKey().getType();
110
         Class<?> type2 = o2.getKey().getType();
112 111

  
113
             if(!type1.equals(type2)) {
114
                 if(type1.equals(FieldUnit.class) || type2.equals(FieldUnit.class)){
115
                     // FieldUnits first
116
                     return type1.equals(FieldUnit.class) ? -1 : 1;
117
                 } else {
118
                     // name types last (in case of missing FieldUnit we expect the base type to be DerivedUnit which comes into the middle)
119
                     return type2.equals(TaxonName.class) || type2.equals(NameTypeDesignation.class) ? -1 : 1;
120
                 }
112
         if(!type1.equals(type2)) {
113
             if(type1.equals(FieldUnit.class) || type2.equals(FieldUnit.class)){
114
                 // FieldUnits first
115
                 return type1.equals(FieldUnit.class) ? -1 : 1;
121 116
             } else {
122
                 return o1.getKey().getLabel().compareTo(o2.getKey().getLabel());
117
                 // name types last (in case of missing FieldUnit we expect the base type to be DerivedUnit which comes into the middle)
118
                 return type2.equals(TaxonName.class) || type2.equals(NameTypeDesignation.class) ? -1 : 1;
123 119
             }
124
         }};
120
         } else {
121
             return o1.getKey().getLabel().compareTo(o2.getKey().getLabel());
122
         }
123
     };
125 124

  
126 125
    /**
127 126
     * Groups the EntityReferences for each of the TypeDesignations by the according TypeDesignationStatus.
......
303 302
    }
304 303

  
305 304
    private LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderByTypeByBaseEntity(
306
            Map<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> stringsByTypeByBaseEntity){
305
            Map<TypedEntityReference<? extends VersionableEntity>,TypeDesignationWorkingSet> stringsByTypeByBaseEntity){
307 306

  
308 307
       // order the FieldUnit TypeName keys
309
       Set<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entrySet = stringsByTypeByBaseEntity.entrySet();
310
       LinkedList<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> baseEntityKeyList = new LinkedList<>(entrySet);
308
       Set<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entrySet
309
               = stringsByTypeByBaseEntity.entrySet();
310
       LinkedList<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> baseEntityKeyList
311
               = new LinkedList<>(entrySet);
311 312
       Collections.sort(baseEntityKeyList, entryComparator);
312 313

  
313 314
       // new LinkedHashMap for the ordered FieldUnitOrTypeName keys

Also available in: Unified diff