Project

General

Profile

« Previous | Next » 

Revision 8c876c41

Added by Andreas Müller almost 9 years ago

fixing infinite loop in HybridRelationship.compareTo #2576

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HybridRelationship.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
32 32
 * The class representing a hybrid relationship between one of the {@link BotanicalName parents}
33 33
 * of a hybrid taxon name and the hybrid taxon name itself. A hybrid taxon name
34 34
 * is a {@link BotanicalName botanical taxon name} assigned to a hybrid plant following
35
 * the {@link NomenclaturalCode#ICBN() ICBN} (Appendix I). A hybrid taxon name must have one 
35
 * the {@link NomenclaturalCode#ICBN() ICBN} (Appendix I). A hybrid taxon name must have one
36 36
 * of the hybrid flags set. The hybrid relationship includes a {@link HybridRelationshipType hybrid relationship type}
37 37
 * (for instance "first parent" or "female parent") and the article of the ICBN
38 38
 * on which the hybrid taxon name relies.
......
41 41
 * <li> Relationship according to the TDWG ontology
42 42
 * <li> TaxonRelationship according to the TCS
43 43
 * </ul>
44
 * 
44
 *
45 45
 * @author m.doering
46 46
 * @version 1.0
47 47
 * @created 08-Nov-2007 13:06:26
......
57 57
@Audited
58 58
public class HybridRelationship extends RelationshipBase<NonViralName, NonViralName, HybridRelationshipType>  implements Cloneable, Comparable<HybridRelationship>{
59 59
	private static final Logger logger = Logger.getLogger(HybridRelationship.class);
60
	
60

  
61 61
	//The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in
62 62
	//the note property.
63 63
	@XmlElement(name = "RuleConsidered")
64 64
	private String ruleConsidered;
65
	
65

  
66 66
	@XmlElement(name = "RelatedFrom")
67 67
    @XmlIDREF
68 68
    @XmlSchemaType(name = "IDREF")
......
76 76
    @ManyToOne(fetch=FetchType.LAZY)
77 77
    @Cascade(CascadeType.SAVE_UPDATE)
78 78
	private NonViralName relatedTo;
79
	
79

  
80 80
    @XmlElement(name = "Type")
81 81
    @XmlIDREF
82 82
    @XmlSchemaType(name = "IDREF")
......
86 86
	/**
87 87
	 * @deprecated for hibernate use only, don't use
88 88
	 */
89
	@Deprecated 
89
	@Deprecated
90 90
	private HybridRelationship(){
91 91
		super();
92 92
	}
93 93

  
94
	
95
	// ************* CONSTRUCTORS *************/	
94

  
95
	// ************* CONSTRUCTORS *************/
96 96
	/**
97 97
	 * Class constructor: creates a new hybrid relationship instance with no
98 98
	 * reference and adds it to the respective
99 99
	 * {@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
100
	 * 
100
	 *
101 101
	 * @param toName			the taxon name to be set as target for the new hybrid relationship
102 102
	 * @param fromName			the taxon name to be set as source for the new hybrid relationship
103 103
	 * @param type				the relationship type to be assigned to the new hybrid relationship
......
108 108
	protected HybridRelationship(NonViralName hybridName, NonViralName parentName, HybridRelationshipType type, String ruleConsidered) {
109 109
		this(hybridName, parentName, type, null, null, ruleConsidered);
110 110
	}
111
	
111

  
112 112
	/**
113 113
	 * Class constructor: creates a new hybrid relationship instance including
114
	 * its {@link eu.etaxonomy.cdm.model.reference.Reference reference source} and adds it to the respective 
114
	 * its {@link eu.etaxonomy.cdm.model.reference.Reference reference source} and adds it to the respective
115 115
	 *{@link BotanicalName#getHybridRelationships() botanical taxon name relation sets} of both involved names.
116
	 * 
116
	 *
117 117
	 * @param toName				the taxon name to be set as target for the new hybrid relationship
118 118
	 * @param fromName				the taxon name to be set as source for the new hybrid relationship
119 119
	 * @param type					the relationship type to be assigned to the new hybrid relationship
......
126 126
	protected HybridRelationship(NonViralName  hybridName, NonViralName parentName, HybridRelationshipType type, Reference citation, String citationMicroReference, String ruleConsidered) {
127 127
		super(parentName, hybridName, type, citation, citationMicroReference);
128 128
		this.setRuleConsidered(ruleConsidered);
129
	}	
130
	
129
	}
130

  
131 131
	//********* METHODS **************************************/
132 132

  
133
	/** 
133
	/**
134 134
	 * Returns the {@link BotanicalName botanical taxon name} that plays the parent role
135 135
	 * in <i>this</i> hybrid relationship.
136
	 *  
136
	 *
137 137
	 * @see   #getHybridName()
138 138
	 * @see   eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedFrom()
139 139
	 */
......
148 148
		this.setRelatedFrom(parentName);
149 149
	}
150 150

  
151
	/** 
151
	/**
152 152
	 * Returns the {@link BotanicalName botanical taxon name} that plays the child role
153 153
	 * (the child is actually the hybrid taxon name) in <i>this</i> hybrid relationship.
154
	 *  
154
	 *
155 155
	 * @see   #getParentName()
156 156
	 * @see   eu.etaxonomy.cdm.model.common.RelationshipBase#getRelatedTo()
157 157
	 */
......
166 166
		this.setRelatedTo(hybridName);
167 167
	}
168 168

  
169
	/** 
169
	/**
170 170
	 * Returns the ICBN rule considered (that is the
171 171
	 * article/note/recommendation in the nomenclatural code) for building
172 172
	 * the string representing the (child) hybrid {@link BotanicalName taxon name}
......
182 182
		this.ruleConsidered = ruleConsidered;
183 183
	}
184 184

  
185
	protected NonViralName getRelatedFrom() {
185
	@Override
186
    protected NonViralName getRelatedFrom() {
186 187
		return relatedFrom;
187 188
	}
188 189

  
189
	protected NonViralName getRelatedTo() {
190
	@Override
191
    protected NonViralName getRelatedTo() {
190 192
		return relatedTo;
191 193
	}
192 194

  
193
	public HybridRelationshipType getType() {
195
	@Override
196
    public HybridRelationshipType getType() {
194 197
		return type;
195 198
	}
196 199

  
197
	protected void setRelatedFrom(NonViralName relatedFrom) {
200
	@Override
201
    protected void setRelatedFrom(NonViralName relatedFrom) {
198 202
		if (relatedFrom == null){
199 203
			this.deletedObjects.add(this.relatedFrom);
200 204
		}
201 205
		this.relatedFrom = relatedFrom;
202 206
	}
203 207

  
204
	protected void setRelatedTo(NonViralName relatedTo) {
208
	@Override
209
    protected void setRelatedTo(NonViralName relatedTo) {
205 210
		if (relatedTo == null){
206 211
			this.deletedObjects.add(this.relatedTo);
207 212
		}
208 213
		this.relatedTo = relatedTo;
209 214
	}
210 215

  
211
	public void setType(HybridRelationshipType type) {
216
	@Override
217
    public void setType(HybridRelationshipType type) {
212 218
		this.type = type;
213 219
	}
214
	
220

  
215 221
// ************************ compareTo *************************************************
216
	/* (non-Javadoc)
217
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
218
	 */
219
//	@Override  //leads to compile errors in some environments
220
	public int compareTo(HybridRelationship rel2) {
222

  
223
	@Override
224
    public int compareTo(HybridRelationship rel2) {
221 225
		HybridRelationshipType type1 = this.getType();
222 226
		HybridRelationshipType type2 = rel2.getType();
223 227
		int compareType = type1.compareTo(type2);
......
230 234
				related1 = this.getRelatedTo();
231 235
				related2 = rel2.getRelatedTo();
232 236
			}
237
			if (related1.equals(related2)){
238
			    return 0;
239
			}
240

  
233 241
			String title1 = related1.getTitleCache();
234 242
			String title2 = related2.getTitleCache();
235 243
			return title1.compareTo(title2);
236 244
		}
237 245
	}
238
	
239
	
246

  
247

  
240 248
//*********************** CLONE ********************************************************/
241
	
242
	/** 
249

  
250
	/**
243 251
	 * Clones <i>this</i> hybrid relationship. This is a shortcut that enables to create
244 252
	 * a new instance that differs only slightly from <i>this</i> hybrid relationship by
245 253
	 * modifying only some of the attributes.<BR>
246
	 * CAUTION: Cloning a relationship will not add the relationship to the according 
254
	 * CAUTION: Cloning a relationship will not add the relationship to the according
247 255
	 * {@link #relatedFrom} and {@link #relatedTo} objects. The method is meant to be used
248 256
	 * mainly for internal purposes (e.g. used within {@link TaxonNameBase#clone()}
249
	 * 
257
	 *
250 258
	 * @see eu.etaxonomy.cdm.model.common.RelationshipBase#clone()
251 259
	 * @see java.lang.Object#clone()
252 260
	 */
......
263 271
			return null;
264 272
		}
265 273
	}
266
	
274

  
267 275
}

Also available in: Unified diff