View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 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.server.Constants;
28  
29  /**
30   * 
31   * @author james
32   *
33   */
34  public class StringClientParam 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, meaning that a value of "smi" would match "smi" and "smith".
49  	 */
50  	public IStringMatch matches() {
51  		return new StringMatches();
52  	}
53  
54  	/**
55  	 * The string matches exactly the given value
56  	 */
57  	public IStringMatch matchesExactly() {
58  		return new StringExactly();
59  	}
60  
61  	public interface IStringMatch {
62  
63  		/**
64  		 * Requests that resources be returned which match the given value
65  		 */
66  		ICriterion<StringClientParam> value(String theValue);
67  
68  		/**
69  		 * Requests that resources be returned which match ANY of the given values (this is an OR search). Note that to specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion)
70  		 * where} criteria with the same parameter.
71  		 */
72  		ICriterion<StringClientParam> values(List<String> theValues);
73  
74  		/**
75  		 * Requests that resources be returned which match the given value
76  		 */
77  		ICriterion<StringClientParam> value(StringDt theValue);
78  
79  		/**
80  		 * Requests that resources be returned which match ANY of the given values (this is an OR search). Note that to specify an AND search, simply add a subsequent {@link IQuery#where(ICriterion)
81  		 * where} criteria with the same parameter.
82  		 */
83  		ICriterion<?> values(String... theValues);
84  
85  	}
86  
87  	private class StringExactly implements IStringMatch {
88  		@Override
89  		public ICriterion<StringClientParam> value(String theValue) {
90  			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
91  		}
92  
93  		@Override
94  		public ICriterion<StringClientParam> value(StringDt theValue) {
95  			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue.getValue());
96  		}
97  
98  		@Override
99  		public ICriterion<StringClientParam> values(List<String> theValue) {
100 			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue);
101 		}
102 
103 		@Override
104 		public ICriterion<?> values(String... theValues) {
105 			return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, Arrays.asList(theValues));
106 		}
107 	}
108 
109 	private class StringMatches implements IStringMatch {
110 		@Override
111 		public ICriterion<StringClientParam> value(String theValue) {
112 			return new StringCriterion<StringClientParam>(getParamName(), theValue);
113 		}
114 
115 		@Override
116 		public ICriterion<StringClientParam> value(StringDt theValue) {
117 			return new StringCriterion<StringClientParam>(getParamName(), theValue.getValue());
118 		}
119 
120 		@Override
121 		public ICriterion<StringClientParam> values(List<String> theValue) {
122 			return new StringCriterion<StringClientParam>(getParamName(), theValue);
123 		}
124 
125 		@Override
126 		public ICriterion<?> values(String... theValues) {
127 			return new StringCriterion<StringClientParam>(getParamName(), Arrays.asList(theValues));
128 		}
129 
130 	}
131 
132 }