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.IQueryParameterAnd;
25  import ca.uhn.fhir.model.api.IQueryParameterOr;
26  import ca.uhn.fhir.rest.api.QualifiedParamList;
27  import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  public abstract class BaseAndListParam<T extends IQueryParameterOr<?>> implements IQueryParameterAnd<T> {
33  
34  	private List<T> myValues = new ArrayList<>();
35  
36  	public abstract BaseAndListParam<T> addAnd(T theValue);
37  
38  	public BaseAndListParam<T> addValue(T theValue) {
39  		myValues.add(theValue);
40  		return this;
41  	}
42  
43  	@Override
44  	public List<T> getValuesAsQueryTokens() {
45  		return myValues;
46  	}
47  
48  	abstract T newInstance();
49  
50  	@Override
51  	public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, List<QualifiedParamList> theParameters) throws InvalidRequestException {
52  		myValues.clear();
53  		for (QualifiedParamList nextParam : theParameters) {
54  			T nextList = newInstance();
55  			nextList.setValuesAsQueryTokens(theContext, theParamName, nextParam);
56  			myValues.add(nextList);
57  		}
58  	}
59  
60  	@Override
61  	public String toString() {
62  		return myValues.toString();
63  	}
64  
65  
66  }