001package ca.uhn.fhir.util;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2020 University Health Network
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.Validate;
024import org.apache.commons.lang3.builder.CompareToBuilder;
025import org.apache.commons.lang3.builder.EqualsBuilder;
026import org.apache.commons.lang3.builder.HashCodeBuilder;
027
028public class VersionIndependentConcept implements Comparable<VersionIndependentConcept> {
029
030        private final String mySystem;
031        private final String myCode;
032        private final String myDisplay;
033        private int myHashCode;
034
035        /**
036         * Constructor
037         */
038        public VersionIndependentConcept(String theSystem, String theCode) {
039                this(theSystem, theCode, null);
040        }
041
042        public VersionIndependentConcept(String theSystem, String theCode, String theDisplay) {
043                mySystem = theSystem;
044                myCode = theCode;
045                myDisplay = theDisplay;
046                myHashCode = new HashCodeBuilder(17, 37)
047                        .append(mySystem)
048                        .append(myCode)
049                        .toHashCode();
050        }
051
052        public String getDisplay() {
053                return myDisplay;
054        }
055
056        public String getSystem() {
057                return mySystem;
058        }
059
060
061        public String getCode() {
062                return myCode;
063        }
064
065        @Override
066        public boolean equals(Object theO) {
067                if (this == theO) {
068                        return true;
069                }
070
071                if (theO == null || getClass() != theO.getClass()) {
072                        return false;
073                }
074
075                VersionIndependentConcept that = (VersionIndependentConcept) theO;
076
077                return new EqualsBuilder()
078                        .append(mySystem, that.mySystem)
079                        .append(myCode, that.myCode)
080                        .isEquals();
081        }
082
083        @Override
084        public int hashCode() {
085                return myHashCode;
086        }
087
088        @Override
089        public int compareTo(VersionIndependentConcept theOther) {
090                CompareToBuilder b = new CompareToBuilder();
091                b.append(mySystem, theOther.getSystem());
092                b.append(myCode, theOther.getCode());
093                return b.toComparison();
094        }
095
096        @Override
097        public String toString() {
098                return "[" + mySystem + "|" + myCode + "]";
099        }
100}