001/* 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.rest.gclient; 021 022import ca.uhn.fhir.rest.param.ParamPrefixEnum; 023 024/** 025 * Token parameter type for use in fluent client interfaces 026 */ 027public class NumberClientParam extends BaseClientParam implements IParam { 028 029 private final String myParamName; 030 031 public NumberClientParam(String theParamName) { 032 myParamName = theParamName; 033 } 034 035 public IMatches<ICriterion<NumberClientParam>> exactly() { 036 return new IMatches<ICriterion<NumberClientParam>>() { 037 @Override 038 public ICriterion<NumberClientParam> number(long theNumber) { 039 return new StringCriterion<>(getParamName(), Long.toString(theNumber)); 040 } 041 042 @Override 043 public ICriterion<NumberClientParam> number(String theNumber) { 044 return new StringCriterion<>(getParamName(), (theNumber)); 045 } 046 }; 047 } 048 049 @Override 050 public String getParamName() { 051 return myParamName; 052 } 053 054 public IMatches<ICriterion<NumberClientParam>> greaterThan() { 055 return new IMatches<ICriterion<NumberClientParam>>() { 056 @Override 057 public ICriterion<NumberClientParam> number(long theNumber) { 058 return new StringCriterion<>(getParamName(), ParamPrefixEnum.GREATERTHAN, Long.toString(theNumber)); 059 } 060 061 @Override 062 public ICriterion<NumberClientParam> number(String theNumber) { 063 return new StringCriterion<>(getParamName(), ParamPrefixEnum.GREATERTHAN, (theNumber)); 064 } 065 }; 066 } 067 068 public IMatches<ICriterion<NumberClientParam>> greaterThanOrEqual() { 069 return new IMatches<ICriterion<NumberClientParam>>() { 070 @Override 071 public ICriterion<NumberClientParam> number(long theNumber) { 072 return new StringCriterion<>( 073 getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, Long.toString(theNumber)); 074 } 075 076 @Override 077 public ICriterion<NumberClientParam> number(String theNumber) { 078 return new StringCriterion<>(getParamName(), ParamPrefixEnum.GREATERTHAN_OR_EQUALS, (theNumber)); 079 } 080 }; 081 } 082 083 public IMatches<ICriterion<NumberClientParam>> lessThan() { 084 return new IMatches<ICriterion<NumberClientParam>>() { 085 @Override 086 public ICriterion<NumberClientParam> number(long theNumber) { 087 return new StringCriterion<>(getParamName(), ParamPrefixEnum.LESSTHAN, Long.toString(theNumber)); 088 } 089 090 @Override 091 public ICriterion<NumberClientParam> number(String theNumber) { 092 return new StringCriterion<>(getParamName(), ParamPrefixEnum.LESSTHAN, (theNumber)); 093 } 094 }; 095 } 096 097 public IMatches<ICriterion<NumberClientParam>> lessThanOrEqual() { 098 return new IMatches<ICriterion<NumberClientParam>>() { 099 @Override 100 public ICriterion<NumberClientParam> number(long theNumber) { 101 return new StringCriterion<>( 102 getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS, Long.toString(theNumber)); 103 } 104 105 @Override 106 public ICriterion<NumberClientParam> number(String theNumber) { 107 return new StringCriterion<>(getParamName(), ParamPrefixEnum.LESSTHAN_OR_EQUALS, (theNumber)); 108 } 109 }; 110 } 111 112 public IMatches<ICriterion<NumberClientParam>> withPrefix(final ParamPrefixEnum thePrefix) { 113 return new IMatches<ICriterion<NumberClientParam>>() { 114 @Override 115 public ICriterion<NumberClientParam> number(long theNumber) { 116 return new StringCriterion<>(getParamName(), thePrefix, Long.toString(theNumber)); 117 } 118 119 @Override 120 public ICriterion<NumberClientParam> number(String theNumber) { 121 return new StringCriterion<>(getParamName(), thePrefix, (theNumber)); 122 } 123 }; 124 } 125 126 public interface IMatches<T> { 127 /** 128 * Creates a search criterion that matches against the given number 129 * 130 * @param theNumber 131 * The number 132 * @return A criterion 133 */ 134 T number(long theNumber); 135 136 /** 137 * Creates a search criterion that matches against the given number 138 * 139 * @param theNumber 140 * The number 141 * @return A criterion 142 */ 143 T number(String theNumber); 144 } 145}