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.jpa.api.pid;
021
022import ca.uhn.fhir.jpa.model.dao.JpaPid;
023import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
024
025import java.util.Objects;
026
027public class TypedResourcePid {
028        public final String resourceType;
029        public final IResourcePersistentId id;
030
031        public TypedResourcePid(String theResourceType, IResourcePersistentId theId) {
032                this.resourceType = theResourceType;
033                this.id = theId;
034        }
035
036        public TypedResourcePid(String theResourceType, Long theId) {
037                this.resourceType = theResourceType;
038                this.id = JpaPid.fromId(theId);
039        }
040
041        @Override
042        public boolean equals(Object o) {
043                if (this == o) return true;
044                if (o == null || getClass() != o.getClass()) return false;
045                TypedResourcePid that = (TypedResourcePid) o;
046                return resourceType.equals(that.resourceType) && id.equals(that.id);
047        }
048
049        @Override
050        public int hashCode() {
051                return Objects.hash(resourceType, id);
052        }
053
054        @Override
055        public String toString() {
056                return resourceType + "[" + id + "]";
057        }
058}