001/*-
002 * #%L
003 * HAPI FHIR JPA Server - International Patient Summary (IPS)
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.ips.jpa;
021
022import org.hl7.fhir.instance.model.api.IBaseResource;
023
024import java.util.Collection;
025import java.util.HashMap;
026import java.util.Map;
027
028public class JpaSectionSearchStrategyCollection {
029
030        private Map<Class<? extends IBaseResource>, Object> mySearchStrategies;
031
032        private JpaSectionSearchStrategyCollection(Map<Class<? extends IBaseResource>, Object> theSearchStrategies) {
033                mySearchStrategies = theSearchStrategies;
034        }
035
036        @SuppressWarnings("unchecked")
037        public <T extends IBaseResource> IJpaSectionSearchStrategy<T> getSearchStrategy(Class<T> theClass) {
038                return (IJpaSectionSearchStrategy<T>) mySearchStrategies.get(theClass);
039        }
040
041        public Collection<Class<? extends IBaseResource>> getResourceTypes() {
042                return mySearchStrategies.keySet();
043        }
044
045        public static JpaSectionSearchStrategyCollectionBuilder newBuilder() {
046                return new JpaSectionSearchStrategyCollectionBuilder();
047        }
048
049        public static class JpaSectionSearchStrategyCollectionBuilder {
050                private Map<Class<? extends IBaseResource>, Object> mySearchStrategies = new HashMap<>();
051
052                public <T extends IBaseResource> JpaSectionSearchStrategyCollectionBuilder addStrategy(
053                                Class<T> theType, IJpaSectionSearchStrategy<T> theSearchStrategy) {
054                        mySearchStrategies.put(theType, theSearchStrategy);
055                        return this;
056                }
057
058                public JpaSectionSearchStrategyCollection build() {
059                        return new JpaSectionSearchStrategyCollection(mySearchStrategies);
060                }
061        }
062}