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