View Javadoc
1   package ca.uhn.fhir.rest.gclient;
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 java.util.Arrays;
24  import java.util.List;
25  
26  import ca.uhn.fhir.model.primitive.StringDt;
27  import ca.uhn.fhir.rest.api.Constants;
28  
29  /**
30   * 
31   * @author james
32   *
33   */
34  public class StringClientParam extends BaseClientParam implements IParam {
35  
36  	private final String myParamName;
37  
38  	public StringClientParam(String theParamName) {
39  		myParamName = theParamName;
40  	}
41  
42  	@Override
43  	public String getParamName() {
44  		return myParamName;
45  	}
46  
47  	/**
48  	 * The string matches the given value (servers will often, but are not required to) implement this as a left match,
49  	 * meaning that a value of "smi" would match "smi" and "smith".
50  	 */
51  	public IStringMatch matches() {
52  		return new StringMatches();
53  	}
54  
55  	/**
56  	 * The string matches exactly the given value
57  	 */
58  	public IStringMatch matchesExactly() {
59  		return new StringExactly();
60  	}
61  
62  	public interface IStringMatch {
63  
64  		/**
65  		 * Requests that resources be returned which match the given value
66  		 */
67  		ICriterion<StringClientParam> value(String theValue);
68  
69  		/**
70  		 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
71  		 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
72  		 * parameter.
73  		 */
74  		ICriterion<StringClientParam> values(List<String> theValues);
75  
76  		/**
77  		 * Requests that resources be returned which match the given value
78  		 */
79  		ICriterion<StringClientParam> value(StringDt theValue);
80  
81  		/**
82  		 * Requests that resources be returned which match ANY of the given values (this is an OR search, not an AND search). Note that to
83  		 * specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion) where} criteria with the same
84  		 * parameter.
85  		 */
86  		ICriterion<?> values(String... theValues);
87  
88  	}
89  
90  	private class StringExactly implements IStringMatch {
91  		@Override
92  		public ICriterion<StringClientParam> value(String theValue) {
93  			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
94  		}
95  
96  		@Override
97  		public ICriterion<StringClientParam> value(StringDt theValue) {
98  			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue.getValue());
99  		}
100 
101 		@Override
102 		public ICriterion<StringClientParam> values(List<String> theValue) {
103 			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
104 		}
105 
106 		@Override
107 		public ICriterion<?> values(String... theValues) {
108 			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, Arrays.asList(theValues));
109 		}
110 	}
111 
112 	private class StringMatches implements IStringMatch {
113 		@Override
114 		public ICriterion<StringClientParam> value(String theValue) {
115 			return new StringCriterion<StringClientParam>(getParamName(), theValue);
116 		}
117 
118 		@Override
119 		public ICriterion<StringClientParam> value(StringDt theValue) {
120 			return new StringCriterion<StringClientParam>(getParamName(), theValue.getValue());
121 		}
122 
123 		@Override
124 		public ICriterion<StringClientParam> values(List<String> theValue) {
125 			return new StringCriterion<StringClientParam>(getParamName(), theValue);
126 		}
127 
128 		@Override
129 		public ICriterion<?> values(String... theValues) {
130 			return new StringCriterion<StringClientParam>(getParamName(), Arrays.asList(theValues));
131 		}
132 
133 	}
134 
135 }