Start work on #50

This commit is contained in:
James Agnew 2014-11-14 10:52:38 -05:00
parent 9fe80dfee1
commit d09e735a3d
3 changed files with 75 additions and 17 deletions

View File

@ -23,23 +23,13 @@ package ca.uhn.fhir.model.api;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import ca.uhn.fhir.parser.DataFormatException;
public abstract class BasePrimitive<T> extends BaseIdentifiableElement implements IPrimitiveDatatype<T> {
@Override
public boolean isEmpty() {
return super.isBaseEmpty() && getValue() == null;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + getValueAsString() + "]";
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(getValue()).toHashCode();
}
private T myCoercedValue;
private String myStringValue;
@Override
public boolean equals(Object theObj) {
if (theObj == null) {
@ -55,4 +45,65 @@ public abstract class BasePrimitive<T> extends BaseIdentifiableElement implement
b.append(getValue(), o.getValue());
return b.isEquals();
}
@Override
public T getValue() {
return myCoercedValue;
}
@Override
public String getValueAsString() throws DataFormatException {
return myStringValue;
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(getValue()).toHashCode();
}
@Override
public boolean isEmpty() {
return super.isBaseEmpty() && getValue() == null;
}
@Override
public void setValue(T theValue) throws DataFormatException {
myCoercedValue = theValue;
if (theValue == null) {
myStringValue = null;
} else {
myStringValue = encode(theValue);
}
}
@Override
public void setValueAsString(String theValue) throws DataFormatException {
myStringValue = theValue;
if (theValue == null) {
myCoercedValue = null;
} else {
myCoercedValue = parse(theValue);
}
}
/**
* Subclasses must override to convert an encoded representation of
* this datatype into a "coerced" one
*
* @param theValue Will not be null
*/
protected abstract T parse(String theValue);
/**
* Subclasses must override to convert a "coerced" value into an
* encoded one.
*
* @param theValue Will not be null
*/
protected abstract String encode(T theValue);
@Override
public String toString() {
return getClass().getSimpleName() + "[" + getValueAsString() + "]";
}
}

View File

@ -70,6 +70,7 @@
<organization>Boston Children's Hospital</organization>
</developer>
<developer>
<id>lmds</id>
<name>Laura MacDougall Sookraj</name>
<organization>University Health Network</organization>
</developer>

View File

@ -7,7 +7,7 @@
</properties>
<body>
<release version="0.8" date="TBD">
<action>
<action tyle="add">
<![CDATA[<b>API CHANGE:</b>]]> The "FHIR structures" for DSTU1 (the classes which model the
resources and composite datatypes) have been moved out of the core JAR into their
own JAR, in order to allow support for DEV resources, and DSTU2 resources when thast
@ -85,7 +85,13 @@
<action type="fix">
Resource fields with a type of "*" (or Any) sometimes failed to parse if a
value type of "code" was used. Thanks to Bill de Beaubien for reporting!
</action>
</action>
<action type="add" dev="lmds">
Remove dependency on JAXB libraries, which were used to parse and encode
dates and times (even in the JSON parser). JAXB is built in to most JDKs
but the version bundled with IBM's JDK is flaky and resulted in a number
of problems when deploying to Websphere.
</action>
</release>
<release version="0.7" date="2014-Oct-23">
<action type="add" issue="30">