Project

General

Profile

Revision 4cf3d32a

ID4cf3d32ab8442f03ef82deac046eeae07eadaa82
Parent 33b908b7
Child 8e6c53f9

Added by Andreas Müller about 5 years ago

Cleanup language string handling and cloning

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/VersionableEntity.java
9 9

  
10 10
package eu.etaxonomy.cdm.model.common;
11 11

  
12
import java.util.HashMap;
13
import java.util.Map;
12 14
import java.util.UUID;
13 15

  
14 16
import javax.persistence.Basic;
......
169 171
		//no changes to: -
170 172
		return result;
171 173
	}
174

  
175

  
176
    /**
177
     * Convenience method to clone a LanguageString map
178
     * @param oldMap
179
     * @return
180
     * @throws CloneNotSupportedException
181
     */
182
    protected Map<Language,LanguageString> cloneLanguageString(Map<Language,LanguageString> oldMap) throws CloneNotSupportedException{
183
        Map<Language,LanguageString> result = new HashMap<>();
184
        for (Language language : oldMap.keySet()){
185
            LanguageString newLanguageString = (LanguageString)oldMap.get(language).clone();
186
            result.put(language, newLanguageString);
187
        }
188
        return result;
189

  
190
    }
172 191
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementBase.java
125 125
    @MapKeyJoinColumn(name="modifyingtext_mapkey_id")
126 126
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
127 127
    @IndexedEmbedded
128
    private Map<Language,LanguageString> modifyingText = new HashMap<Language,LanguageString>();
128
    private Map<Language,LanguageString> modifyingText = new HashMap<>();
129 129

  
130 130
    @XmlElementWrapper(name = "Media")
131 131
    @XmlElement(name = "Medium")
......
501 501
        }
502 502

  
503 503
        //modifying text
504
        result.modifyingText = new HashMap<Language, LanguageString>();
505
        for (Language language : getModifyingText().keySet()){
506
            //TODO clone needed? See also IndividualsAssociation
507
            LanguageString newLanguageString = (LanguageString)getModifyingText().get(language).clone();
508
            result.modifyingText.put(language, newLanguageString);
509
        }
504
        result.modifyingText = cloneLanguageString(getModifyingText());
510 505

  
511 506
        //modifiers
512 507
        result.modifiers = new HashSet<DefinedTerm>();
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/IndividualsAssociation.java
74 74
	@MapKeyJoinColumn(name="description_mapkey_id")
75 75
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE })
76 76
	@JoinTable(name = "IndividualsAssociation_LanguageString")  //to distinguish from other DescriptionElementBase_LanguageString cases
77
	private Map<Language,LanguageString> description = new HashMap<Language,LanguageString>();
77
	private Map<Language,LanguageString> description = new HashMap<>();
78 78

  
79 79
	@XmlElement(name = "AssociatedSpecimenOrObservation")
80 80
	@XmlIDREF
......
229 229
			IndividualsAssociation result = (IndividualsAssociation)super.clone();
230 230

  
231 231
			//description
232
			result.description = new HashMap<Language, LanguageString>();
233
			for (Language language : getDescription().keySet()){
234
				//TODO clone needed?
235
				LanguageString newLanguageString = (LanguageString)getDescription().get(language).clone();
236
				result.description.put(language, newLanguageString);
237
			}
238

  
232
			result.description = cloneLanguageString(getDescription());
239 233

  
240 234
			return result;
241 235
			//no changes to: associatedSpecimenOrObservation
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/KeyStatement.java
6 6
import java.util.HashMap;
7 7
import java.util.List;
8 8
import java.util.Map;
9
import java.util.Map.Entry;
10 9

  
11 10
import javax.persistence.Entity;
12 11
import javax.persistence.FetchType;
......
290 289
		try {
291 290
			result = (KeyStatement) super.clone();
292 291

  
293
			result.label = new HashMap<Language, LanguageString>();
294

  
295

  
296
			for (Entry<Language,LanguageString> entry: this.label.entrySet()){
297

  
298
				result.label.put(entry.getKey(), entry.getValue());
299
			}
292
			result.label = cloneLanguageString(this.label);
300 293

  
301 294
			return result;
302 295
		}catch (CloneNotSupportedException e) {
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/StateData.java
106 106
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
107 107
    @Field(name="modifyingText")
108 108
    @FieldBridge(impl=MultilanguageTextFieldBridge.class)
109
    private Map<Language,LanguageString> modifyingText = new HashMap<Language,LanguageString>();
109
    private Map<Language,LanguageString> modifyingText = new HashMap<>();
110 110

  
111 111
//********************* FACTORY METHODS ************************\
112 112

  
......
318 318
            }
319 319

  
320 320
            //modifying text
321
            result.modifyingText = new HashMap<Language, LanguageString>();
322
            for (Language language : getModifyingText().keySet()){
323
                //TODO clone needed? See also IndividualsAssociation
324
                LanguageString newLanguageString = (LanguageString)getModifyingText().get(language).clone();
325
                result.modifyingText.put(language, newLanguageString);
326
            }
321
            result.modifyingText = cloneLanguageString(this.modifyingText);
327 322

  
328 323
            return result;
329 324
            //no changes to: state
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/TaxonInteraction.java
77 77
	@MapKeyJoinColumn(name="description_mapkey_id")
78 78
    @JoinTable(name = "TaxonInteraction_LanguageString")  //to distinguish from other DescriptionElementBase_LanguageString
79 79
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE})
80
    private Map<Language,LanguageString> description = new HashMap<Language,LanguageString>();
80
    private Map<Language,LanguageString> description = new HashMap<>();
81 81

  
82 82
	@XmlElement(name = "Taxon2")
83 83
	@XmlIDREF
......
248 248
			TaxonInteraction result = (TaxonInteraction)super.clone();
249 249

  
250 250
			//description
251
			result.description = new HashMap<Language, LanguageString>();
252
			for (Language language : getDescriptions().keySet()){
253
				//TODO clone needed? See also IndividualsAssociation
254
				LanguageString newLanguageString = (LanguageString)getDescriptions().get(language).clone();
255
				result.description.put(language, newLanguageString);
256
			}
257

  
251
			result.description = cloneLanguageString(getDescriptions());
258 252

  
259 253
			return result;
260 254
			//no changes to: taxon2
......
264 258
			return null;
265 259
		}
266 260
	}
261

  
267 262
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/media/Media.java
98 98
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE,CascadeType.DELETE, CascadeType.REFRESH})
99 99
    @NotNull
100 100
    @NotEmpty(groups = Level2.class)
101
    private Map<Language,LanguageString> title = new HashMap<Language,LanguageString>();
101
    private Map<Language,LanguageString> title = new HashMap<>();
102 102

  
103 103
    //creation date of the media (not of the record)
104 104
    @XmlElement(name = "MediaCreated", type= String.class)
......
117 117
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE,CascadeType.DELETE, CascadeType.REFRESH})
118 118
    @IndexedEmbedded
119 119
    @NotNull
120
    private Map<Language,LanguageString> description = new HashMap<Language,LanguageString>();
120
    private Map<Language,LanguageString> description = new HashMap<>();
121 121

  
122 122
    //A single medium such as a picture can have multiple representations in files.
123 123
    //Common are multiple resolutions or file formats for images for example
......
356 356

  
357 357
    public Map<Language,LanguageString> getAllDescriptions(){
358 358
        if(this.description == null) {
359
            this.description = new HashMap<Language,LanguageString>();
359
            this.description = new HashMap<>();
360 360
        }
361 361
        return this.description;
362 362
    }
......
387 387
    public Object clone() throws CloneNotSupportedException{
388 388
        Media result = (Media)super.clone();
389 389
        //description
390
        result.description = new HashMap<Language, LanguageString>();
391
        for (Language language: this.description.keySet()){
392
            result.description.put(language, this.description.get(language));
393
        }
390
        result.description = cloneLanguageString(this.description);
391

  
394 392
        //title
395
        result.title = new HashMap<Language, LanguageString>();
396
        for (Language language: this.title.keySet()){
397
            result.title.put(language, this.title.get(language));
398
        }
393
        result.title = cloneLanguageString(this.title);
394

  
399 395
        //media representations
400
        result.representations = new HashSet<MediaRepresentation>();
396
        result.representations = new HashSet<>();
401 397
        for (MediaRepresentation mediaRepresentation: this.representations){
402 398
            result.representations.add((MediaRepresentation)mediaRepresentation.clone());
403 399
        }
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/occurrence/SpecimenOrObservationBase.java
197 197
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE, CascadeType.DELETE})
198 198
    @IndexedEmbedded
199 199
    @NotNull
200
    protected Map<Language,LanguageString> definition = new HashMap<Language,LanguageString>();
200
    protected Map<Language,LanguageString> definition = new HashMap<>();
201 201

  
202 202
    // events that created derivedUnits from this unit
203 203
    @XmlElementWrapper(name = "DerivationEvents")
......
594 594
        result = (SpecimenOrObservationBase)super.clone();
595 595

  
596 596
        //defininion (description, languageString)
597
        result.definition = new HashMap<Language,LanguageString>();
598
        for(LanguageString languageString : this.definition.values()) {
599
            LanguageString newLanguageString = (LanguageString)languageString.clone();
600
            result.putDefinition(newLanguageString);
601
        }
597
        result.definition = cloneLanguageString(this.definition);
602 598

  
603 599
        //sex
604 600
        result.setSex(this.sex);
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Classification.java
124 124
	@JoinTable(name = "Classification_Description")
125 125
//	@Field(name="text", store=Store.YES)
126 126
//    @FieldBridge(impl=MultilanguageTextFieldBridge.class)
127
    private final Map<Language,LanguageString> description = new HashMap<Language,LanguageString>();
127
    private final Map<Language,LanguageString> description = new HashMap<>();
128 128

  
129 129

  
130 130

  
......
671 671
        try{
672 672
            result = (Classification)super.clone();
673 673
            //result.rootNode.childNodes = new ArrayList<TaxonNode>();
674
            List<TaxonNode> rootNodes = new ArrayList<TaxonNode>();
674
            List<TaxonNode> rootNodes = new ArrayList<>();
675 675
            TaxonNode rootNodeClone;
676 676

  
677 677

  
......
679 679
            TaxonNode rootNode;
680 680
            Iterator<TaxonNode> iterator = rootNodes.iterator();
681 681

  
682
            result.description = cloneLanguageString(this.description);
683

  
682 684
            while (iterator.hasNext()){
683 685
                rootNode = iterator.next();
684 686
                rootNodeClone = rootNode.cloneDescendants();
......
688 690
            }
689 691

  
690 692
            //geo-scopes
691
            result.geoScopes = new HashSet<NamedArea>();
693
            result.geoScopes = new HashSet<>();
692 694
            for (NamedArea namedArea : getGeoScopes()){
693 695
                result.geoScopes.add(namedArea);
694 696
            }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)