View Javadoc
1   package ca.uhn.fhir.rest.param;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.context.FhirContext;
24  import ca.uhn.fhir.model.api.IQueryParameterOr;
25  import ca.uhn.fhir.model.api.IQueryParameterType;
26  import ca.uhn.fhir.rest.api.QualifiedParamList;
27  
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  abstract class BaseOrListParam<MT extends BaseOrListParam<?, ?>, PT extends IQueryParameterType> implements IQueryParameterOr<PT> {
32  
33  	private List<PT> myList = new ArrayList<>();
34  
35  	@SuppressWarnings("unchecked")
36  	public MT add(PT theParameter) {
37  		if (theParameter != null) {
38  			myList.add(theParameter);
39  		}
40  		return (MT) this;
41  	}
42  
43  	public abstract MT addOr(PT theParameter);
44  
45  	@Override
46  	public List<PT> getValuesAsQueryTokens() {
47  		return myList;
48  	}
49  
50  	abstract PT newInstance();
51  
52  	@Override
53  	public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, QualifiedParamList theParameters) {
54  		myList.clear();
55  		for (String next : theParameters) {
56  			PT nextParam = newInstance();
57  			nextParam.setValueAsQueryToken(theContext, theParamName, theParameters.getQualifier(), next);
58  			myList.add(nextParam);
59  		}
60  	}
61  
62  	@Override
63  	public String toString() {
64  		return myList.toString();
65  	}
66  
67  }