View Javadoc
1   package ca.uhn.fhir.jpa.term;
2   
3   /*
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2019 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.apache.commons.lang3.builder.CompareToBuilder;
24  import org.apache.commons.lang3.builder.EqualsBuilder;
25  import org.apache.commons.lang3.builder.HashCodeBuilder;
26  
27  public class VersionIndependentConcept implements Comparable<VersionIndependentConcept> {
28  
29  	private final String mySystem;
30  	private final String myCode;
31  	private int myHashCode;
32  
33  	/**
34  	 * Constructor
35  	 */
36  	public VersionIndependentConcept(String theSystem, String theCode) {
37  		mySystem = theSystem;
38  		myCode = theCode;
39  		myHashCode = new HashCodeBuilder(17, 37)
40  			.append(mySystem)
41  			.append(myCode)
42  			.toHashCode();
43  	}
44  
45  	public String getSystem() {
46  		return mySystem;
47  	}
48  
49  
50  	public String getCode() {
51  		return myCode;
52  	}
53  
54  	@Override
55  	public boolean equals(Object theO) {
56  		if (this == theO) {
57  			return true;
58  		}
59  
60  		if (theO == null || getClass() != theO.getClass()) {
61  			return false;
62  		}
63  
64  		VersionIndependentConcept that = (VersionIndependentConcept) theO;
65  
66  		return new EqualsBuilder()
67  			.append(mySystem, that.mySystem)
68  			.append(myCode, that.myCode)
69  			.isEquals();
70  	}
71  
72  	@Override
73  	public int hashCode() {
74  		return myHashCode;
75  	}
76  
77  	@Override
78  	public int compareTo(VersionIndependentConcept theOther) {
79  		CompareToBuilder b = new CompareToBuilder();
80  		b.append(mySystem, theOther.getSystem());
81  		b.append(myCode, theOther.getCode());
82  		return b.toComparison();
83  	}
84  }