001package ca.uhn.fhir.rest.gclient;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2016 University Health Network
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import java.util.Arrays;
024import java.util.List;
025
026import ca.uhn.fhir.model.primitive.StringDt;
027
028/**
029 *
030 */
031public class UriClientParam extends BaseClientParam  implements IParam {
032
033        //TODO: handle :above and :below
034        
035        private final String myParamName;
036
037        public UriClientParam(String theParamName) {
038                myParamName = theParamName;
039        }
040
041        @Override
042        public String getParamName() {
043                return myParamName;
044        }
045
046        /**
047         * 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".
048         */
049        public IUriMatch matches(String theValue) {
050                return new UriMatches();
051        }
052
053
054        public interface IUriMatch {
055
056                /**
057                 * Requests that resources be returned which match the given value
058                 */
059                ICriterion<UriClientParam> value(String theValue);
060
061                /**
062                 * 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)
063                 * where} criteria with the same parameter.
064                 */
065                ICriterion<UriClientParam> values(List<String> theValues);
066
067                /**
068                 * Requests that resources be returned which match the given value
069                 */
070                ICriterion<UriClientParam> value(StringDt theValue);
071
072                /**
073                 * 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)
074                 * where} criteria with the same parameter.
075                 */
076                ICriterion<?> values(String... theValues);
077
078        }
079
080        private class UriMatches implements IUriMatch {
081                @Override
082                public ICriterion<UriClientParam> value(String theValue) {
083                        return new StringCriterion<UriClientParam>(getParamName(), theValue);
084                }
085
086                @Override
087                public ICriterion<UriClientParam> value(StringDt theValue) {
088                        return new StringCriterion<UriClientParam>(getParamName(), theValue.getValue());
089                }
090
091                @Override
092                public ICriterion<UriClientParam> values(List<String> theValue) {
093                        return new StringCriterion<UriClientParam>(getParamName(), theValue);
094                }
095
096                @Override
097                public ICriterion<?> values(String... theValues) {
098                        return new StringCriterion<UriClientParam>(getParamName(), Arrays.asList(theValues));
099                }
100
101        }
102
103}