Revision dc59a89a
Added by Andreas Kohlbecker almost 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/TypeDesignationConverter.java | ||
---|---|---|
57 | 57 |
|
58 | 58 |
private Collection<TypeDesignationBase> typeDesignations; |
59 | 59 |
|
60 |
private int workingSetIdAutoIncrement = 0; |
|
61 |
|
|
60 | 62 |
/** |
61 | 63 |
* Groups the EntityReferences for each of the TypeDesignations by the according TypeDesignationStatus. |
62 | 64 |
* The TypeDesignationStatusBase keys are already ordered by the term order defined in the vocabulary. |
... | ... | |
140 | 142 |
// order the FieldUnit TypeName keys |
141 | 143 |
List<TypedEntityReference> baseEntityKeyList = new LinkedList<>(stringsByTypeByBaseEntity.keySet()); |
142 | 144 |
Collections.sort(baseEntityKeyList, new Comparator<TypedEntityReference>(){ |
145 |
/** |
|
146 |
* Sorts the base entitoes (TypedEntityReference) in nthe following order: |
|
147 |
* |
|
148 |
* 1. FieldUnits |
|
149 |
* 2. DerivedUnit (in case of missing FieldUnit we expect the base type to be DerivedUnit) |
|
150 |
* 3. NameType |
|
151 |
* |
|
152 |
* {@inheritDoc} |
|
153 |
*/ |
|
143 | 154 |
@Override |
144 | 155 |
public int compare(TypedEntityReference o1, TypedEntityReference o2) { |
145 | 156 |
if(!o1.getType().equals(o2.getType())) { |
146 |
return o1.getType().equals(FieldUnit.class) ? -1 : 1; |
|
157 |
if(o1.equals(FieldUnit.class) || o2.equals(FieldUnit.class)){ |
|
158 |
// FieldUnits first |
|
159 |
return o1.getType().equals(FieldUnit.class) ? -1 : 1; |
|
160 |
} else { |
|
161 |
// name types last (in case of missing FieldUnit we expect the base type to be DerivedUnit which comes into the middle) |
|
162 |
return o2.getType().equals(TaxonName.class) ? -1 : 1; |
|
163 |
} |
|
164 |
} else { |
|
165 |
return o1.getLabel().compareTo(o2.getLabel()); |
|
147 | 166 |
} |
148 |
return o1.getLabel().compareTo(o2.getLabel()); |
|
149 | 167 |
}}); |
150 | 168 |
|
151 | 169 |
// new LinkedHashMap for the ordered FieldUnitOrTypeName keys |
... | ... | |
157 | 175 |
// order the TypeDesignationStatusBase keys |
158 | 176 |
List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(typeDesignationWorkingSet.keySet()); |
159 | 177 |
Collections.sort(keyList, new Comparator<TypeDesignationStatusBase>() { |
178 |
@SuppressWarnings("unchecked") |
|
160 | 179 |
@Override |
161 | 180 |
public int compare(TypeDesignationStatusBase o1, TypeDesignationStatusBase o2) { |
162 | 181 |
// fix inverted order of cdm terms by -1* |
... | ... | |
165 | 184 |
}); |
166 | 185 |
// new LinkedHashMap for the ordered TypeDesignationStatusBase keys |
167 | 186 |
TypeDesignationWorkingSet orderedStringsByOrderedTypes = new TypeDesignationWorkingSet(typeDesignationWorkingSet.getContainigEntityReference(), baseEntityRef); |
187 |
orderedStringsByOrderedTypes.setWorkingSetId(typeDesignationWorkingSet.workingSetId); // preserve original workingSetId |
|
168 | 188 |
keyList.forEach(key -> orderedStringsByOrderedTypes.put(key, typeDesignationWorkingSet.get(key))); |
169 | 189 |
stringsOrderedbyBaseEntityOrderdByType.put(baseEntityRef, orderedStringsByOrderedTypes); |
170 | 190 |
} |
... | ... | |
319 | 339 |
return typeDesignations; |
320 | 340 |
} |
321 | 341 |
|
342 |
/** |
|
343 |
* @param ref |
|
344 |
* @return |
|
345 |
*/ |
|
346 |
public TypeDesignationBase findTypeDesignation(EntityReference typeDesignationRef) { |
|
347 |
for(TypeDesignationBase td : typeDesignations){ |
|
348 |
if(td.getId() == typeDesignationRef.getId()){ |
|
349 |
return td; |
|
350 |
} |
|
351 |
} |
|
352 |
// TODO Auto-generated method stub |
|
353 |
return null; |
|
354 |
} |
|
355 |
|
|
356 |
|
|
322 | 357 |
public LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> getOrderdTypeDesignationWorkingSets() { |
323 | 358 |
return orderedByTypesByBaseEntity; |
324 | 359 |
} |
... | ... | |
477 | 512 |
|
478 | 513 |
TypedEntityReference baseEntityReference; |
479 | 514 |
|
515 |
int workingSetId = workingSetIdAutoIncrement++; |
|
516 |
|
|
480 | 517 |
private static final long serialVersionUID = -1329007606500890729L; |
481 | 518 |
|
482 | 519 |
/** |
... | ... | |
508 | 545 |
get(status).add(typeDesignationEntityReference); |
509 | 546 |
} |
510 | 547 |
|
548 |
/** |
|
549 |
* @return the workingSetId |
|
550 |
*/ |
|
551 |
public int getWorkingSetId() { |
|
552 |
return workingSetId; |
|
553 |
} |
|
554 |
|
|
555 |
/** |
|
556 |
* @param workingSetId the workingSetId to set |
|
557 |
*/ |
|
558 |
public void setWorkingSetId(int workingSetId) { |
|
559 |
this.workingSetId = workingSetId; |
|
560 |
} |
|
561 |
|
|
511 | 562 |
public String getRepresentation() { |
512 | 563 |
return workingSetRepresentation; |
513 | 564 |
} |
Also available in: Unified diff
ref #6719 deterministic sortorder when base enitity is TaxonName (NameTypes)