001/*-
002 * #%L
003 * HAPI FHIR Storage api
004 * %%
005 * Copyright (C) 2014 - 2024 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 ca.uhn.fhir.i18n.Msg;
023import ca.uhn.fhir.model.api.IElement;
024import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
025import ca.uhn.fhir.model.primitive.StringDt;
026import ca.uhn.fhir.model.primitive.UriDt;
027import org.apache.commons.lang3.builder.EqualsBuilder;
028import org.apache.commons.lang3.builder.HashCodeBuilder;
029
030import java.util.List;
031
032/**
033 * Version independent identifier
034 */
035public class CanonicalIdentifier extends BaseIdentifierDt {
036        UriDt mySystem;
037        StringDt myValue;
038
039        @Override
040        public UriDt getSystemElement() {
041                return mySystem;
042        }
043
044        @Override
045        public StringDt getValueElement() {
046                return myValue;
047        }
048
049        @Override
050        public CanonicalIdentifier setSystem(String theUri) {
051                mySystem = new UriDt((theUri));
052                return this;
053        }
054
055        @Override
056        public CanonicalIdentifier setValue(String theString) {
057                myValue = new StringDt(theString);
058                return this;
059        }
060
061        @Override
062        public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
063                throw new UnsupportedOperationException(Msg.code(1488));
064        }
065
066        @Override
067        public boolean isEmpty() {
068                if (mySystem != null && !mySystem.isEmpty()) {
069                        return false;
070                }
071                if (myValue != null && !myValue.isEmpty()) {
072                        return false;
073                }
074                return true;
075        }
076
077        @Override
078        public boolean equals(Object theO) {
079                if (this == theO) return true;
080
081                if (theO == null || getClass() != theO.getClass()) return false;
082
083                CanonicalIdentifier that = (CanonicalIdentifier) theO;
084
085                return new EqualsBuilder()
086                                .append(mySystem, that.mySystem)
087                                .append(myValue, that.myValue)
088                                .isEquals();
089        }
090
091        @Override
092        public int hashCode() {
093                return new HashCodeBuilder(17, 37).append(mySystem).append(myValue).toHashCode();
094        }
095}