private DescriptionBaseDto description;
private TaxonNodeDto taxonNode;
- private Map<UUID, DescriptionElementDto> featureToElementMap;
+ private Map<UUID, Set<DescriptionElementDto>> featureToElementMap;
private Map<UUID, Collection<String>> featureToDisplayDataMap;
public RowWrapperDTO(DescriptionBaseDto specimenDescription, TaxonNodeDto taxonNode) {
for (DescriptionElementDto descriptionElementBase : elements) {
// if(hasData(descriptionElementBase)){
UUID featureUuid = descriptionElementBase.getFeatureUuid();
- featureToElementMap.put(featureUuid, descriptionElementBase);
+ addToFeatureToElementMap(featureUuid, descriptionElementBase);
+
Collection<String> displayData = generateDisplayString(descriptionElementBase);
if(displayData!=null){
- featureToDisplayDataMap.put(featureUuid, displayData);
+ addDisplayStringsToMap(featureUuid, displayData);
}
}
}
}
+ /**
+ * @param featureUuid
+ * @param displayData
+ */
+ private void addDisplayStringsToMap(UUID featureUuid, Collection<String> displayData) {
+ if (featureToDisplayDataMap.get(featureUuid) == null){
+ featureToDisplayDataMap.put(featureUuid, new HashSet<>());
+ }
+ featureToDisplayDataMap.get(featureUuid).addAll(displayData);
+ }
+
public QuantitativeDataDto addQuantitativeData(FeatureDto feature){
QuantitativeDataDto data = new QuantitativeDataDto(feature);
description.addElement(data);
- featureToElementMap.put(feature.getUuid(), data);
+ addToFeatureToElementMap(feature.getUuid(), data);
return data;
}
+ /**
+ * @param feature
+ * @param data
+ */
+ private void addToFeatureToElementMap(UUID featureUuid, DescriptionElementDto data) {
+ if (featureToElementMap.get(featureUuid) == null){
+ featureToElementMap.put(featureUuid, new HashSet<>());
+ }
+ featureToElementMap.get(featureUuid).add(data);
+ }
+
public CategoricalDataDto addCategoricalData(FeatureDto feature){
CategoricalDataDto data = new CategoricalDataDto(feature);
description.addElement(data);
- featureToElementMap.put(feature.getUuid(), data);
+ addToFeatureToElementMap(feature.getUuid(), data);
return data;
}
return featureToDisplayDataMap.get(featureUuid);
}
- public DescriptionElementDto getDataValueForFeature(UUID featureUuid){
- DescriptionElementDto descriptionElementBase = featureToElementMap.get(featureUuid);
+ public Set<DescriptionElementDto> getDataValueForFeature(UUID featureUuid){
+ Set<DescriptionElementDto> descriptionElementBase = featureToElementMap.get(featureUuid);
return descriptionElementBase;
}
}
public void setDataValueForCategoricalData(UUID featureUuid, List<TermDto> states){
- DescriptionElementDto descriptionElementBase = featureToElementMap.get(featureUuid);
+ Set<DescriptionElementDto> descriptionElementBase = featureToElementMap.get(featureUuid);
if(states.isEmpty()){
removeFeature(featureUuid, descriptionElementBase);
}
removeElementForFeature(featureUuid);
description.getElements().add(categoricalData);
- featureToElementMap.put(featureUuid, categoricalData);
+ addToFeatureToElementMap(featureUuid, categoricalData);
+
// update display data cache
- featureToDisplayDataMap.put(featureUuid, generateDisplayString(categoricalData));
+ addDisplayStringsToMap(featureUuid, generateDisplayString(categoricalData));
+// featureToDisplayDataMap.put(featureUuid, generateDisplayString(categoricalData));
}
/**
description.getElements().remove(oldElement);
}
- private void removeFeature(UUID featureUuid, DescriptionElementDto descriptionElementBase) {
- DescriptionElementDto element = featureToElementMap.get(featureUuid);
- if (element == null){
+ private void removeFeature(UUID featureUuid, Set<DescriptionElementDto> descriptionElementBases) {
+ Set<DescriptionElementDto> elements = featureToElementMap.get(featureUuid);
+ if (elements == null){
return;
}
- int i = 0;
-
+ Integer i = 0;
+ Set<Integer> indices = new HashSet<>();
for (DescriptionElementDto dto: description.getElements()){
- if (dto.getFeatureUuid() != null && dto.getFeatureUuid().equals(descriptionElementBase.getFeatureUuid())){
- break;
+ for (DescriptionElementDto descElDto: descriptionElementBases) {
+ if (dto.getFeatureUuid() != null && dto.getFeatureUuid().equals(descElDto.getFeatureUuid())){
+ indices.add(i);
+ break;
+ }
}
-
i++;
}
-
- description.getElements().remove(i);
+ for (Integer index: indices){
+ description.getElements().remove(index);
+ }
featureToElementMap.remove(featureUuid);
featureToDisplayDataMap.remove(featureUuid);
}
public void setDataValueForQuantitativeData(UUID featureUuid, Map<TermDto, List<String>> textFields, TermDto unit){
- DescriptionElementDto descriptionElementBase = featureToElementMap.get(featureUuid);
+ Set<DescriptionElementDto> descriptionElementBase = featureToElementMap.get(featureUuid);
if(textFields.values().stream().allMatch(listOfStrings->listOfStrings.isEmpty())){
removeFeature(featureUuid, descriptionElementBase);
return;
quantitativeData.setValues(tempValues);
removeElementForFeature(featureUuid);
description.getElements().add(quantitativeData);
- featureToElementMap.put(featureUuid, quantitativeData);
- featureToDisplayDataMap.put(featureUuid, generateDisplayString(quantitativeData));
+ addToFeatureToElementMap(featureUuid, quantitativeData);
+ addDisplayStringsToMap(featureUuid, generateDisplayString(quantitativeData));
+// featureToDisplayDataMap.put(featureUuid, generateDisplayString(quantitativeData));
}
@Override