View Javadoc
1   package ca.uhn.fhir.rest.gclient;
2   
3   import ca.uhn.fhir.rest.param.ParamPrefixEnum;
4   
5   /*
6    * #%L
7    * HAPI FHIR - Core Library
8    * %%
9    * Copyright (C) 2014 - 2018 University Health Network
10   * %%
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   * 
15   *      http://www.apache.org/licenses/LICENSE-2.0
16   * 
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License.
22   * #L%
23   */
24  
25  /**
26   * Token parameter type for use in fluent client interfaces
27   */
28  public class NumberClientParam extends BaseClientParam  implements IParam {
29  
30  	private String myParamName;
31  
32  	public NumberClientParam(String theParamName) {
33  		myParamName = theParamName;
34  	}
35  
36  	public IMatches<ICriterion<NumberClientParam>> exactly() {
37  		return new IMatches<ICriterion<NumberClientParam>>() {
38  			@Override
39  			public ICriterion<NumberClientParam> number(long theNumber) {
40  				return new StringCriterion<NumberClientParam>(getParamName(), Long.toString(theNumber));
41  			}
42  
43  			@Override
44  			public ICriterion<NumberClientParam> number(String theNumber) {
45  				return new StringCriterion<NumberClientParam>(getParamName(), (theNumber));
46  			}
47  		};
48  	}
49  
50  	@Override
51  	public String getParamName() {
52  		return myParamName;
53  	}
54  
55  	public IMatches<ICriterion<NumberClientParam>> greaterThan() {
56  		return new IMatches<ICriterion<NumberClientParam>>() {
57  			@Override
58  			public ICriterion<NumberClientParam> number(long theNumber) {
59  				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN, Long.toString(theNumber));
60  			}
61  
62  			@Override
63  			public ICriterion<NumberClientParam> number(String theNumber) {
64  				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN, (theNumber));
65  			}
66  		};
67  	}
68  
69  	public IMatches<ICriterion<NumberClientParam>> greaterThanOrEqual() {
70  		return new IMatches<ICriterion<NumberClientParam>>() {
71  			@Override
72  			public ICriterion<NumberClientParam> number(long theNumber) {
73  				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, Long.toString(theNumber));
74  			}
75  
76  			@Override
77  			public ICriterion<NumberClientParam> number(String theNumber) {
78  				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, (theNumber));
79  			}
80  		};
81  	}
82  
83  	public IMatches<ICriterion<NumberClientParam>> lessThan() {
84  		return new IMatches<ICriterion<NumberClientParam>>() {
85  			@Override
86  			public ICriterion<NumberClientParam> number(long theNumber) {
87  				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN, Long.toString(theNumber));
88  			}
89  
90  			@Override
91  			public ICriterion<NumberClientParam> number(String theNumber) {
92  				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN, (theNumber));
93  			}
94  		};
95  	}
96  
97  	public IMatches<ICriterion<NumberClientParam>> lessThanOrEqual() {
98  		return new IMatches<ICriterion<NumberClientParam>>() {
99  			@Override
100 			public ICriterion<NumberClientParam> number(long theNumber) {
101 				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS, Long.toString(theNumber));
102 			}
103 
104 			@Override
105 			public ICriterion<NumberClientParam> number(String theNumber) {
106 				return new StringCriterion<NumberClientParam>(getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS,  (theNumber));
107 			}
108 		};
109 	}
110 
111 	public IMatches<ICriterion<NumberClientParam>> withPrefix(final ParamPrefixEnum thePrefix) {
112 		return new IMatches<ICriterion<NumberClientParam>>() {
113 			@Override
114 			public ICriterion<NumberClientParam> number(long theNumber) {
115 				return new StringCriterion<NumberClientParam>(getParamName(), thePrefix, Long.toString(theNumber));
116 			}
117 
118 			@Override
119 			public ICriterion<NumberClientParam> number(String theNumber) {
120 				return new StringCriterion<NumberClientParam>(getParamName(), thePrefix,  (theNumber));
121 			}
122 		};
123 	}
124 
125 	public interface IMatches<T> {
126 		/**
127 		 * Creates a search criterion that matches against the given number
128 		 * 
129 		 * @param theNumber
130 		 *            The number
131 		 * @return A criterion
132 		 */
133 		T number(long theNumber);
134 
135 		/**
136 		 * Creates a search criterion that matches against the given number
137 		 * 
138 		 * @param theNumber
139 		 *            The number
140 		 * @return A criterion
141 		 */
142 		T number(String theNumber);
143 	}
144 
145 }