View Javadoc
1   package ca.uhn.fhir.model.primitive;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 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 org.apache.commons.lang3.StringUtils;
24  
25  import ca.uhn.fhir.context.FhirContext;
26  import ca.uhn.fhir.model.api.BasePrimitive;
27  import ca.uhn.fhir.model.api.IQueryParameterType;
28  import ca.uhn.fhir.model.api.annotation.DatatypeDef;
29  import ca.uhn.fhir.model.api.annotation.SimpleSetter;
30  import ca.uhn.fhir.rest.param.StringParam;
31  
32  @DatatypeDef(name = "string")
33  public class StringDt extends BasePrimitive<String> implements IQueryParameterType {
34  
35  	/**
36  	 * Create a new String
37  	 */
38  	public StringDt() {
39  		super();
40  	}
41  
42  	/**
43  	 * Create a new String
44  	 */
45  	@SimpleSetter
46  	public StringDt(@SimpleSetter.Parameter(name = "theString") String theValue) {
47  		setValue(theValue);
48  	}
49  
50  	public String getValueNotNull() {
51  		return StringUtils.defaultString(getValue());
52  	}
53  
54  	/**
55  	 * Returns the value of this string, or <code>null</code>
56  	 */
57  	@Override
58  	public String toString() {
59  		return getValue();
60  	}
61  
62  	@Override
63  	public int hashCode() {
64  		final int prime = 31;
65  		int result = 1;
66  		result = prime * result + ((getValue() == null) ? 0 : getValue().hashCode());
67  		return result;
68  	}
69  
70  	@Override
71  	public boolean equals(Object obj) {
72  		if (this == obj)
73  			return true;
74  		if (obj == null)
75  			return false;
76  		if (getClass() != obj.getClass())
77  			return false;
78  		StringDt other = (StringDt) obj;
79  		if (getValue() == null) {
80  			if (other.getValue() != null)
81  				return false;
82  		} else if (!getValue().equals(other.getValue()))
83  			return false;
84  		return true;
85  	}
86  
87  	/**
88  	 * {@inheritDoc}
89  	 */
90  	@Override
91  	public void setValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) {
92  		setValue(theValue);
93  	}
94  
95  	/**
96  	 * {@inheritDoc}
97  	 */
98  	@Override
99  	public String getValueAsQueryToken(FhirContext theContext) {
100 		return getValue();
101 	}
102 
103 	/**
104 	 * Returns <code>true</code> if this datatype has no extensions, and has either a <code>null</code> value or an empty ("") value.
105 	 */
106 	@Override
107 	public boolean isEmpty() {
108 		boolean retVal = super.isBaseEmpty() && StringUtils.isBlank(getValue());
109 		return retVal;
110 	}
111 
112 	@Override
113 	public String getQueryParameterQualifier() {
114 		return null;
115 	}
116 
117 	@Override
118 	protected String parse(String theValue) {
119 		return theValue;
120 	}
121 
122 	@Override
123 	protected String encode(String theValue) {
124 		return theValue;
125 	}
126 
127 	/**
128 	 * <b>Not supported!</b>
129 	 * 
130 	 * @deprecated get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you
131 	 * need this functionality
132 	 */
133 	@Deprecated
134 	@Override
135 	public Boolean getMissing() {
136 		return null;
137 	}
138 
139 	/**
140 	 * <b>Not supported!</b>
141 	 * 
142 	 * @deprecated get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you
143 	 * need this functionality
144 	 */
145 	@Deprecated
146 	@Override
147 	public IQueryParameterType setMissing(Boolean theMissing) {
148 		throw new UnsupportedOperationException("get/setMissing is not supported in StringDt. Use {@link StringParam} instead if you need this functionality");
149 	}
150 
151 }