001package ca.uhn.fhir.rest.server;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2016 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 java.util.LinkedHashMap;
024
025import ca.uhn.fhir.model.api.IQueryParameterType;
026import ca.uhn.fhir.rest.param.BaseAndListParam;
027import ca.uhn.fhir.rest.param.CompositeAndListParam;
028import ca.uhn.fhir.rest.param.CompositeOrListParam;
029import ca.uhn.fhir.rest.param.DateAndListParam;
030import ca.uhn.fhir.rest.param.DateOrListParam;
031import ca.uhn.fhir.rest.param.NumberAndListParam;
032import ca.uhn.fhir.rest.param.NumberOrListParam;
033import ca.uhn.fhir.rest.param.QuantityAndListParam;
034import ca.uhn.fhir.rest.param.QuantityOrListParam;
035import ca.uhn.fhir.rest.param.ReferenceAndListParam;
036import ca.uhn.fhir.rest.param.ReferenceOrListParam;
037import ca.uhn.fhir.rest.param.StringAndListParam;
038import ca.uhn.fhir.rest.param.StringOrListParam;
039import ca.uhn.fhir.rest.param.TokenAndListParam;
040import ca.uhn.fhir.rest.param.TokenOrListParam;
041import ca.uhn.fhir.rest.param.UriAndListParam;
042import ca.uhn.fhir.rest.param.UriOrListParam;
043
044public class SearchParameterMap extends LinkedHashMap<String, BaseAndListParam<?>> {
045
046        private static final long serialVersionUID = 1L;
047
048        public <A extends IQueryParameterType, B extends IQueryParameterType> void add(String theName, CompositeOrListParam<A, B> theCompositeOrListParam) {
049                @SuppressWarnings("unchecked")
050                CompositeAndListParam<A, B> andList = (CompositeAndListParam<A, B>) get(theName);
051                if (andList == null) {
052                        andList = new CompositeAndListParam<A, B>(theCompositeOrListParam.getLeftType(), theCompositeOrListParam.getRightType());
053                        put(theName, andList);
054                }
055                andList.addValue(theCompositeOrListParam);
056        }
057
058        public void add(String theName, DateOrListParam theOrListParam) {
059                DateAndListParam andList = (DateAndListParam) get(theName);
060                if (andList == null) {
061                        andList = new DateAndListParam();
062                        put(theName, andList);
063                }
064                andList.addValue(theOrListParam);
065        }
066
067        public void add(String theName, NumberOrListParam theOrListParam) {
068                NumberAndListParam andList = (NumberAndListParam) get(theName);
069                if (andList == null) {
070                        andList = new NumberAndListParam();
071                        put(theName, andList);
072                }
073                andList.addValue(theOrListParam);
074        }
075
076        public void add(String theName, QuantityOrListParam theOrListParam) {
077                QuantityAndListParam andList = (QuantityAndListParam) get(theName);
078                if (andList == null) {
079                        andList = new QuantityAndListParam();
080                        put(theName, andList);
081                }
082                andList.addValue(theOrListParam);
083        }
084
085        public void add(String theName, ReferenceOrListParam theOrListParam) {
086                ReferenceAndListParam andList = (ReferenceAndListParam) get(theName);
087                if (andList == null) {
088                        andList = new ReferenceAndListParam();
089                        put(theName, andList);
090                }
091                andList.addValue(theOrListParam);
092        }
093
094        public void add(String theName, StringOrListParam theOrListParam) {
095                StringAndListParam andList = (StringAndListParam) get(theName);
096                if (andList == null) {
097                        andList = new StringAndListParam();
098                        put(theName, andList);
099                }
100                andList.addValue(theOrListParam);
101        }
102
103        public void add(String theName, TokenOrListParam theOrListParam) {
104                TokenAndListParam andList = (TokenAndListParam) get(theName);
105                if (andList == null) {
106                        andList = new TokenAndListParam();
107                        put(theName, andList);
108                }
109                andList.addValue(theOrListParam);
110        }
111
112        public void add(String theName, UriOrListParam theOrListParam) {
113                UriAndListParam andList = (UriAndListParam) get(theName);
114                if (andList == null) {
115                        andList = new UriAndListParam();
116                        put(theName, andList);
117                }
118                andList.addValue(theOrListParam);
119        }
120
121        // public void add(String theName, IQueryParameterOr<?> theOr) {
122        // if (theOr == null) {
123        // return;
124        // }
125        //
126        // switch (theOr.getClass()) {
127        //
128        // }
129        //
130        // if (!containsKey(theName)) {
131        // put(theName, new ArrayList<List<? extends IQueryParameterType>>());
132        // }
133        //
134        // StringAndListParam
135        //
136        // IQueryParameterAnd<IQueryParameterOr<?>> and = get(theName);
137        // and.add(theOr);
138        // }
139
140}