Move precision checking code to setValueAsString

This commit is contained in:
dotasek 2022-03-15 16:49:51 -04:00
parent 6730275277
commit 1a7e076479
6 changed files with 24 additions and 25 deletions

View File

@ -180,9 +180,7 @@ public class VersionConvertorPrimitiveTypeTests {
org.hl7.fhir.r4.model.InstantType.class, org.hl7.fhir.r4.model.Type.class, org.hl7.fhir.r4.model.InstantType.class, org.hl7.fhir.r4.model.Type.class,
org.hl7.fhir.r5.model.InstantType.class, org.hl7.fhir.r5.model.DataType.class, org.hl7.fhir.r5.model.InstantType.class, org.hl7.fhir.r5.model.DataType.class,
INSTANT_PRECISION_STRINGS) INSTANT_PRECISION_STRINGS)
).flatMap(i -> i); ).flatMap(i -> i);
} }
@ParameterizedTest(name = "Test index: {index} ConvertorFactory={0} First Class={1} First Value={3} Second Class={4} Second Value={6}") @ParameterizedTest(name = "Test index: {index} ConvertorFactory={0} First Class={1} First Value={3} Second Class={4} Second Value={6}")

View File

@ -129,9 +129,6 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
*/ */
public BaseDateTimeType(String theString) { public BaseDateTimeType(String theString) {
setValueAsString(theString); setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new IllegalArgumentException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
/** /**
@ -465,9 +462,12 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
} }
@Override @Override
public void setValueAsString(String theValue) throws IllegalArgumentException { public void setValueAsString(String theString) throws IllegalArgumentException {
clearTimeZone(); clearTimeZone();
super.setValueAsString(theValue); super.setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new IllegalArgumentException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
/** /**

View File

@ -100,9 +100,6 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
*/ */
public BaseDateTimeType(String theString) { public BaseDateTimeType(String theString) {
setValueAsString(theString); setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
private void clearTimeZone() { private void clearTimeZone() {
@ -478,9 +475,12 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
} }
@Override @Override
public void setValueAsString(String theValue) throws DataFormatException { public void setValueAsString(String theString) throws DataFormatException {
clearTimeZone(); clearTimeZone();
super.setValueAsString(theValue); super.setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new DataFormatException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
private void throwBadDateFormat(String theValue) { private void throwBadDateFormat(String theValue) {

View File

@ -99,7 +99,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
*/ */
public BaseDateTimeType(String theString) { public BaseDateTimeType(String theString) {
setValueAsString(theString); setValueAsString(theString);
validatePrecisionAndThrowDataFormatException(theString, getPrecision());
} }
/** /**
@ -710,9 +710,10 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
} }
@Override @Override
public void setValueAsString(String theValue) throws DataFormatException { public void setValueAsString(String theString) throws DataFormatException {
clearTimeZone(); clearTimeZone();
super.setValueAsString(theValue); super.setValueAsString(theString);
validatePrecisionAndThrowDataFormatException(theString, getPrecision());
} }
protected void setValueAsV3String(String theV3String) { protected void setValueAsV3String(String theV3String) {

View File

@ -100,9 +100,6 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
*/ */
public BaseDateTimeType(String theString) { public BaseDateTimeType(String theString) {
setValueAsString(theString); setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new IllegalArgumentException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
/** /**
@ -709,9 +706,12 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
} }
@Override @Override
public void setValueAsString(String theValue) throws DataFormatException { public void setValueAsString(String theString) throws DataFormatException {
clearTimeZone(); clearTimeZone();
super.setValueAsString(theValue); super.setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new IllegalArgumentException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
protected void setValueAsV3String(String theV3String) { protected void setValueAsV3String(String theV3String) {

View File

@ -100,9 +100,6 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
*/ */
public BaseDateTimeType(String theString) { public BaseDateTimeType(String theString) {
setValueAsString(theString); setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new IllegalArgumentException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
/** /**
@ -716,9 +713,12 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
} }
@Override @Override
public void setValueAsString(String theValue) throws DataFormatException { public void setValueAsString(String theString) throws DataFormatException {
clearTimeZone(); clearTimeZone();
super.setValueAsString(theValue); super.setValueAsString(theString);
if (isPrecisionAllowed(getPrecision()) == false) {
throw new IllegalArgumentException("Invalid date/time string (datatype " + getClass().getSimpleName() + " does not support " + getPrecision() + " precision): " + theString);
}
} }
protected void setValueAsV3String(String theV3String) { protected void setValueAsV3String(String theV3String) {