001package ca.uhn.fhir.rest.param;
002
003/*-
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
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.*;
024
025/**
026 * Comparator/qualifier for values used in REST params, such as {@link DateParam}, {@link NumberParam}, and
027 * {@link QuantityParam}
028 * 
029 * @since 1.5
030 */
031public enum ParamPrefixEnum {
032
033        /**
034         * Code Value: <b>eq</b>
035         *
036         * The actual value is equal to the given value
037         */
038        APPROXIMATE("ap"),
039
040        /**
041         * Code Value: <b>eb</b>
042         *
043         * The range of the search value does overlap not with the range of the target value, and the range above the search value contains the range of the target value
044         */
045        ENDS_BEFORE("eb"),
046
047        /**
048         * Code Value: <b>eq</b>
049         *
050         * The actual value is equal to the given value
051         */
052        EQUAL("eq"),
053
054        /**
055         * Code Value: <b>gt</b>
056         *
057         * The actual value is greater than the given value.
058         */
059        GREATERTHAN("gt"),
060
061        /**
062         * Code Value: <b>ge</b>
063         *
064         * The actual value is greater than or equal to the given value.
065         */
066        GREATERTHAN_OR_EQUALS("ge"),
067
068        /**
069         * Code Value: <b>lt</b>
070         *
071         * The actual value is less than the given value.
072         */
073        LESSTHAN("lt"),
074
075        /**
076         * Code Value: <b>le</b>
077         *
078         * The actual value is less than or equal to the given value.
079         */
080        LESSTHAN_OR_EQUALS("le"), 
081        
082        /**
083         * Code Value: <b>ne</b>
084         *
085         * The actual value is not equal to the given value
086         */
087        NOT_EQUAL("ne"),
088        
089        /**
090         * Code Value: <b>sa</b>
091         *
092         * The range of the search value does not overlap with the range of the target value, and the range below the search value contains the range of the target value
093         */
094        STARTS_AFTER("sa");
095        
096        private static final Map<String, ParamPrefixEnum> VALUE_TO_PREFIX;
097
098        static {
099                HashMap<String, ParamPrefixEnum> valueToPrefix = new HashMap<String, ParamPrefixEnum>();
100                for (ParamPrefixEnum next : values()) {
101                        valueToPrefix.put(next.getValue(), next);
102                }
103
104                VALUE_TO_PREFIX = Collections.unmodifiableMap(valueToPrefix);
105        }
106
107        private final String myValue;
108
109        private ParamPrefixEnum(String theValue) {
110                myValue = theValue;
111        }
112
113        /**
114         * Returns the value, e.g. <code>lt</code> or <code>eq</code>
115         */
116        public String getValue() {
117                return myValue;
118        }
119
120        /**
121         * Returns the prefix associated with a given DSTU2+ value (e.g. <code>lt</code> or <code>eq</code>)
122         * 
123         * @param theValue
124         *           e.g. <code>&lt;</code> or <code>~</code>
125         * @return The prefix, or <code>null</code> if no prefix matches the value
126         */
127        public static ParamPrefixEnum forValue(String theValue) {
128                return VALUE_TO_PREFIX.get(theValue);
129        }
130}