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