001/* 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.util; 021 022import org.apache.commons.lang3.builder.CompareToBuilder; 023import org.apache.commons.lang3.builder.EqualsBuilder; 024import org.apache.commons.lang3.builder.HashCodeBuilder; 025 026public class FhirVersionIndependentConcept implements Comparable<FhirVersionIndependentConcept> { 027 028 private final String mySystem; 029 private final String mySystemVersion; 030 private final String myCode; 031 private final String myDisplay; 032 private int myHashCode; 033 034 /** 035 * Constructor 036 */ 037 public FhirVersionIndependentConcept(String theSystem, String theCode) { 038 this(theSystem, theCode, null); 039 } 040 041 public FhirVersionIndependentConcept(String theSystem, String theCode, String theDisplay) { 042 this(theSystem, theCode, theDisplay, null); 043 } 044 045 public FhirVersionIndependentConcept(String theSystem, String theCode, String theDisplay, String theSystemVersion) { 046 mySystem = theSystem; 047 mySystemVersion = theSystemVersion; 048 myCode = theCode; 049 myDisplay = theDisplay; 050 myHashCode = new HashCodeBuilder(17, 37) 051 .append(mySystem) 052 .append(myCode) 053 .toHashCode(); 054 } 055 056 public String getDisplay() { 057 return myDisplay; 058 } 059 060 public String getSystem() { 061 return mySystem; 062 } 063 064 public String getSystemVersion() { 065 return mySystemVersion; 066 } 067 068 public String getCode() { 069 return myCode; 070 } 071 072 @Override 073 public boolean equals(Object theO) { 074 if (this == theO) { 075 return true; 076 } 077 078 if (theO == null || getClass() != theO.getClass()) { 079 return false; 080 } 081 082 FhirVersionIndependentConcept that = (FhirVersionIndependentConcept) theO; 083 084 return new EqualsBuilder() 085 .append(mySystem, that.mySystem) 086 .append(myCode, that.myCode) 087 .isEquals(); 088 } 089 090 @Override 091 public int hashCode() { 092 return myHashCode; 093 } 094 095 @Override 096 public int compareTo(FhirVersionIndependentConcept theOther) { 097 CompareToBuilder b = new CompareToBuilder(); 098 b.append(mySystem, theOther.getSystem()); 099 b.append(myCode, theOther.getCode()); 100 return b.toComparison(); 101 } 102 103 @Override 104 public String toString() { 105 return "[" + mySystem + "|" + myCode + "]"; 106 } 107}