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 static org.apache.commons.lang3.StringUtils.*;
24  import ca.uhn.fhir.model.api.BasePrimitive;
25  import ca.uhn.fhir.model.api.annotation.DatatypeDef;
26  import ca.uhn.fhir.model.api.annotation.SimpleSetter;
27  import ca.uhn.fhir.parser.DataFormatException;
28  
29  @DatatypeDef(name = "code")
30  public class CodeDt extends BasePrimitive<String> implements ICodedDatatype, Comparable<CodeDt> {
31  
32  	private String myValue;
33  
34  	/**
35  	 * Constructor
36  	 */
37  	public CodeDt() {
38  		super();
39  	}
40  
41  	/**
42  	 * Constructor which accepts a string code
43  	 */
44  	@SimpleSetter()
45  	public CodeDt(@SimpleSetter.Parameter(name = "theCode") String theCode) {
46  		setValue(theCode);
47  	}
48  
49  	@Override
50  	public String getValue() {
51  		return myValue;
52  	}
53  
54  	@Override
55  	public void setValue(String theValue) throws DataFormatException {
56  		if (theValue == null) {
57  			myValue = null;
58  		} else {
59  			String newValue = theValue.trim();
60  			myValue = newValue;
61  		}
62  	}
63  
64  	@Override
65  	public void setValueAsString(String theValue) throws DataFormatException {
66  		setValue(theValue);
67  	}
68  
69  	@Override
70  	public String getValueAsString() {
71  		return getValue();
72  	}
73  
74  	@Override
75  	public int compareTo(CodeDt theCode) {
76  		if (theCode == null) {
77  			return 1;
78  		}
79  		return defaultString(getValue()).compareTo(defaultString(theCode.getValue()));
80  	}
81  
82  }