From 0f799833cc3a61db641db1f92a3f753d0a0e15fe Mon Sep 17 00:00:00 2001 From: Lee Surprenant Date: Sun, 25 Apr 2021 09:06:56 -0400 Subject: [PATCH] issue #1814 - add javadoc and requireNonNull in factory methods Signed-off-by: Lee Surprenant --- .../com/ibm/fhir/model/type/Base64Binary.java | 6 +- .../java/com/ibm/fhir/model/type/Boolean.java | 14 ++ .../com/ibm/fhir/model/type/Canonical.java | 34 ++++ .../java/com/ibm/fhir/model/type/Code.java | 21 +++ .../java/com/ibm/fhir/model/type/Date.java | 14 ++ .../com/ibm/fhir/model/type/DateTime.java | 24 +++ .../java/com/ibm/fhir/model/type/Decimal.java | 21 +++ .../main/java/com/ibm/fhir/model/type/Id.java | 14 ++ .../java/com/ibm/fhir/model/type/Instant.java | 24 +++ .../java/com/ibm/fhir/model/type/Integer.java | 21 +++ .../com/ibm/fhir/model/type/Markdown.java | 14 ++ .../java/com/ibm/fhir/model/type/Oid.java | 14 ++ .../com/ibm/fhir/model/type/PositiveInt.java | 21 +++ .../java/com/ibm/fhir/model/type/String.java | 14 ++ .../java/com/ibm/fhir/model/type/Time.java | 14 ++ .../com/ibm/fhir/model/type/UnsignedInt.java | 21 +++ .../java/com/ibm/fhir/model/type/Uri.java | 14 ++ .../java/com/ibm/fhir/model/type/Url.java | 14 ++ .../java/com/ibm/fhir/model/type/Uuid.java | 14 ++ .../java/com/ibm/fhir/model/type/Xhtml.java | 9 +- .../com/ibm/fhir/model/test/DateTimeTest.java | 18 +- .../util/test/ValidationSupportTest.java | 58 +++---- .../com/ibm/fhir/tools/CodeGenerator.java | 161 ++++++++++++++++-- 23 files changed, 526 insertions(+), 53 deletions(-) diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Base64Binary.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Base64Binary.java index 1972b742783..a3e3a5ea1ff 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Base64Binary.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Base64Binary.java @@ -55,9 +55,10 @@ public boolean hasChildren() { * Factory method for creating Base64Binary objects from a byte array; this array should be the actual value. * * @param value - * The byte array of to-be-encoded content + * The byte array of to-be-encoded content, not null */ public static Base64Binary of(byte[] value) { + Objects.requireNonNull(value, "value"); return Base64Binary.builder().value(value).build(); } @@ -65,9 +66,10 @@ public static Base64Binary of(byte[] value) { * Factory method for creating Base64Binary objects from a Base64 encoded value. * * @param value - * The Base64 encoded string + * The Base64 encoded string, not null */ public static Base64Binary of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Base64Binary.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Boolean.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Boolean.java index 2067fca9e22..45d7ce5cc31 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Boolean.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Boolean.java @@ -52,11 +52,25 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating Boolean objects from a java.lang.Boolean + * + * @param value + * A java.lang.Boolean, not null + */ public static Boolean of(java.lang.Boolean value) { + Objects.requireNonNull(value, "value"); return Boolean.builder().value(value).build(); } + /** + * Factory method for creating Boolean objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed into a java.lang.Boolean, not null + */ public static Boolean of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Boolean.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Canonical.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Canonical.java index 7c567d993f1..b51c0e4279b 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Canonical.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Canonical.java @@ -29,11 +29,27 @@ public boolean hasValue() { return (value != null); } + /** + * Factory method for creating Canonical objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Canonical of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Canonical.builder().value(value).build(); } + /** + * Factory method for creating Canonical objects from a java.lang.String uri and version + * + * @param value + * A java.lang.String for the uri portion of the canonical reference, not null + * @param value + * A java.lang.String for the version portion of the canonical reference + */ public static Canonical of(java.lang.String uri, java.lang.String version) { + Objects.requireNonNull(uri, "uri"); StringBuilder value = new StringBuilder(uri); if (version != null && !version.isEmpty()) { value.append('|'); @@ -42,7 +58,18 @@ public static Canonical of(java.lang.String uri, java.lang.String version) { return Canonical.builder().value(value.toString()).build(); } + /** + * Factory method for creating Canonical objects from a java.lang.String uri, version, and fragment + * + * @param value + * A java.lang.String for the uri portion of the canonical reference, not null + * @param value + * A java.lang.String for the version portion of the canonical reference + * @param value + * A java.lang.String for the fragment portion of the canonical reference + */ public static Canonical of(java.lang.String uri, java.lang.String version, java.lang.String fragment) { + Objects.requireNonNull(uri, "uri"); StringBuilder value = new StringBuilder(uri); if (version != null && !version.isEmpty()) { value.append('|'); @@ -55,7 +82,14 @@ public static Canonical of(java.lang.String uri, java.lang.String version, java. return Canonical.builder().value(value.toString()).build(); } + /** + * Factory method for creating Canonical objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a valid FHIR uri value, not null + */ public static Uri uri(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Canonical.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Code.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Code.java index 4aa5d2bf94d..f2f75e0d9c0 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Code.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Code.java @@ -32,15 +32,36 @@ public boolean hasValue() { return (value != null); } + /** + * Factory method for creating Code objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Code of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Code.builder().value(value).build(); } + /** + * Factory method for creating Code objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static String string(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Code.builder().value(value).build(); } + /** + * Factory method for creating Code objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a valid FHIR code value, not null + */ public static Code code(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Code.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Date.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Date.java index 9984133e962..5a4a336c625 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Date.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Date.java @@ -62,11 +62,25 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating Date objects from a TemporalAccessor + * + * @param value + * A TemporalAccessor, not null + */ public static Date of(TemporalAccessor value) { + Objects.requireNonNull(value, "value"); return Date.builder().value(value).build(); } + /** + * Factory method for creating Date objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed by {@link #PARSER_FORMATTER}, not null + */ public static Date of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Date.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/DateTime.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/DateTime.java index 40aea18d5a5..f041e2fa7fd 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/DateTime.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/DateTime.java @@ -73,19 +73,43 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating DateTime objects from a TemporalAccessor + * + * @param value + * A TemporalAccessor, not null + */ public static DateTime of(TemporalAccessor value) { + Objects.requireNonNull(value, "value"); return DateTime.builder().value(value).build(); } + /** + * Factory method for creating DateTime objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed by {@link #PARSER_FORMATTER}, not null + */ public static DateTime of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return DateTime.builder().value(value).build(); } + /** + * Factory method for creating a DateTime that represents the current DateTime + */ public static DateTime now() { return DateTime.builder().value(ZonedDateTime.now()).build(); } + /** + * Factory method for creating a DateTime that represents the current DateTime in the passed time zone + * + * @param offset + * The ZoneOffset for the desired time zone, not null + */ public static DateTime now(ZoneOffset offset) { + Objects.requireNonNull(offset, "offset"); return DateTime.builder().value(ZonedDateTime.now(offset)).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Decimal.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Decimal.java index d21453dc2fc..dbc79f86cc3 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Decimal.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Decimal.java @@ -50,15 +50,36 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating Decimal objects from a BigDecimal + * + * @param value + * A BigDecimal, not null + */ public static Decimal of(BigDecimal value) { + Objects.requireNonNull(value, "value"); return Decimal.builder().value(value).build(); } + /** + * Factory method for creating Decimal objects from a Number + * + * @param value + * A Number, not null + */ public static Decimal of(Number value) { + Objects.requireNonNull(value, "value"); return Decimal.builder().value(value.toString()).build(); } + /** + * Factory method for creating Decimal objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed into a BigDecimal, not null + */ public static Decimal of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Decimal.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Id.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Id.java index f94e86c1855..a681b2199f4 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Id.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Id.java @@ -32,11 +32,25 @@ public boolean hasValue() { return (value != null); } + /** + * Factory method for creating Id objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Id of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Id.builder().value(value).build(); } + /** + * Factory method for creating Id objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static String string(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Id.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Instant.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Instant.java index 444865d7cbb..839fa1469b7 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Instant.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Instant.java @@ -61,19 +61,43 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating Instant objects from a ZonedDateTime + * + * @param value + * A ZonedDateTime, not null + */ public static Instant of(ZonedDateTime value) { + Objects.requireNonNull(value, "value"); return Instant.builder().value(value).build(); } + /** + * Factory method for creating Instant objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed by {@link #PARSER_FORMATTER}, not null + */ public static Instant of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Instant.builder().value(value).build(); } + /** + * Factory method for creating a Instant that represents the current Instant + */ public static Instant now() { return Instant.builder().value(ZonedDateTime.now()).build(); } + /** + * Factory method for creating a Instant that represents the current Instant in the passed time zone + * + * @param offset + * the ZoneOffset for the desired time zone, not null + */ public static Instant now(ZoneOffset offset) { + Objects.requireNonNull(offset, "offset"); return Instant.builder().value(ZonedDateTime.now(offset)).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Integer.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Integer.java index b79d2bb263e..304402e897f 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Integer.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Integer.java @@ -49,15 +49,36 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating Integer objects from a java.lang.Integer + * + * @param value + * A java.lang.Integer, not null + */ public static Integer of(java.lang.Integer value) { + Objects.requireNonNull(value, "value"); return Integer.builder().value(value).build(); } + /** + * Factory method for creating Integer objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed into a java.lang.Integer, not null + */ public static Integer of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Integer.builder().value(value).build(); } + /** + * Factory method for creating Integer objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a java.lang.Integer, not null + */ public static Integer integer(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Integer.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Markdown.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Markdown.java index 94b4fb3f324..2bcd1ab80e1 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Markdown.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Markdown.java @@ -29,11 +29,25 @@ public boolean hasValue() { return (value != null); } + /** + * Factory method for creating Markdown objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Markdown of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Markdown.builder().value(value).build(); } + /** + * Factory method for creating Markdown objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static String string(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Markdown.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Oid.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Oid.java index f476d0425a9..13132af4d48 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Oid.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Oid.java @@ -34,11 +34,25 @@ public boolean hasValue() { return (value != null); } + /** + * Factory method for creating Oid objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Oid of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Oid.builder().value(value).build(); } + /** + * Factory method for creating Oid objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a valid FHIR uri value, not null + */ public static Uri uri(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Oid.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/PositiveInt.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/PositiveInt.java index e5506a015ab..1887c22ccd2 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/PositiveInt.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/PositiveInt.java @@ -39,15 +39,36 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating PositiveInt objects from a java.lang.Integer + * + * @param value + * A java.lang.Integer, not null + */ public static PositiveInt of(java.lang.Integer value) { + Objects.requireNonNull(value, "value"); return PositiveInt.builder().value(value).build(); } + /** + * Factory method for creating PositiveInt objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed into a java.lang.Integer, not null + */ public static PositiveInt of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return PositiveInt.builder().value(value).build(); } + /** + * Factory method for creating PositiveInt objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a java.lang.Integer, not null + */ public static Integer integer(java.lang.String value) { + Objects.requireNonNull(value, "value"); return PositiveInt.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/String.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/String.java index a8223e21b67..77bc6531147 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/String.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/String.java @@ -50,11 +50,25 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating String objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static String of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return String.builder().value(value).build(); } + /** + * Factory method for creating String objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static String string(java.lang.String value) { + Objects.requireNonNull(value, "value"); return String.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Time.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Time.java index a1e2477da6c..fcc802fddd4 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Time.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Time.java @@ -60,11 +60,25 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating Time objects from a LocalTime + * + * @param value + * A LocalTime, not null + */ public static Time of(LocalTime value) { + Objects.requireNonNull(value, "value"); return Time.builder().value(value).build(); } + /** + * Factory method for creating Time objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed by {@link #PARSER_FORMATTER}, not null + */ public static Time of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Time.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/UnsignedInt.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/UnsignedInt.java index f760cf436f2..e99be694b0a 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/UnsignedInt.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/UnsignedInt.java @@ -39,15 +39,36 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating UnsignedInt objects from a java.lang.Integer + * + * @param value + * A java.lang.Integer, not null + */ public static UnsignedInt of(java.lang.Integer value) { + Objects.requireNonNull(value, "value"); return UnsignedInt.builder().value(value).build(); } + /** + * Factory method for creating UnsignedInt objects from a java.lang.String + * + * @param value + * A java.lang.String value that can be parsed into a java.lang.Integer, not null + */ public static UnsignedInt of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return UnsignedInt.builder().value(value).build(); } + /** + * Factory method for creating UnsignedInt objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a java.lang.Integer, not null + */ public static Integer integer(java.lang.String value) { + Objects.requireNonNull(value, "value"); return UnsignedInt.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Uri.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Uri.java index 7c9d618275f..c5f18105d3f 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Uri.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Uri.java @@ -50,11 +50,25 @@ public boolean hasChildren() { return super.hasChildren(); } + /** + * Factory method for creating Uri objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Uri of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Uri.builder().value(value).build(); } + /** + * Factory method for creating Uri objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a valid FHIR uri value, not null + */ public static Uri uri(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Uri.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Url.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Url.java index 53a1c2f35ee..87c354388ca 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Url.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Url.java @@ -29,11 +29,25 @@ public boolean hasValue() { return (value != null); } + /** + * Factory method for creating Url objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Url of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Url.builder().value(value).build(); } + /** + * Factory method for creating Url objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a valid FHIR uri value, not null + */ public static Uri uri(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Url.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Uuid.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Uuid.java index a2ff85e709e..9a0fb5158eb 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Uuid.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Uuid.java @@ -34,11 +34,25 @@ public boolean hasValue() { return (value != null); } + /** + * Factory method for creating Uuid objects from a java.lang.String + * + * @param value + * A java.lang.String, not null + */ public static Uuid of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Uuid.builder().value(value).build(); } + /** + * Factory method for creating Uuid objects from a java.lang.String + * + * @param value + * A java.lang.String that can be parsed into a valid FHIR uri value, not null + */ public static Uri uri(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Uuid.builder().value(value).build(); } diff --git a/fhir-model/src/main/java/com/ibm/fhir/model/type/Xhtml.java b/fhir-model/src/main/java/com/ibm/fhir/model/type/Xhtml.java index 7bc295bebe9..609dc6c03e0 100644 --- a/fhir-model/src/main/java/com/ibm/fhir/model/type/Xhtml.java +++ b/fhir-model/src/main/java/com/ibm/fhir/model/type/Xhtml.java @@ -61,9 +61,10 @@ public boolean hasChildren() { * Factory method for creating Xhtml objects from an XHTML java.lang.String * * @param value - * A java.lang.String with valid XHTML content + * A java.lang.String with valid XHTML content, not null */ public static Xhtml of(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Xhtml.builder().value(value).build(); } @@ -71,9 +72,10 @@ public static Xhtml of(java.lang.String value) { * Factory method for creating Xhtml objects from an XHTML java.lang.String * * @param value - * A java.lang.String with valid XHTML content + * A java.lang.String with valid XHTML content, not null */ public static Xhtml xhtml(java.lang.String value) { + Objects.requireNonNull(value, "value"); return Xhtml.builder().value(value).build(); } @@ -84,9 +86,10 @@ public static Xhtml xhtml(java.lang.String value) { * then wrap it in an XHTML {@code
} element with a namespace of {@code http://www.w3.org/1999/xhtml} * * @param plainText - * The text to encode and wrap for use within a Narrative + * The text to encode and wrap for use within a Narrative, not null */ public static Xhtml from(java.lang.String plainText) { + Objects.requireNonNull(plainText, "plainText"); return Xhtml.builder().value(DIV_OPEN + Encode.forHtmlContent(plainText) + DIV_CLOSE).build(); } diff --git a/fhir-model/src/test/java/com/ibm/fhir/model/test/DateTimeTest.java b/fhir-model/src/test/java/com/ibm/fhir/model/test/DateTimeTest.java index 2f008e57e21..76e77c450e4 100644 --- a/fhir-model/src/test/java/com/ibm/fhir/model/test/DateTimeTest.java +++ b/fhir-model/src/test/java/com/ibm/fhir/model/test/DateTimeTest.java @@ -76,7 +76,7 @@ public void testInstantStringInputWithWrongSeperator() throws Exception { public void testInstantStringInputWithShortDateValue() throws Exception { Instant.of("2018-2-3T20:00:00-04:00"); } - + @Test(groups = { "instant-tests" }, expectedExceptions = DateTimeParseException.class) public void testInstantStringInputWithWrongChars() throws Exception { Instant.of("2018-aa-bbT20:00:00-04:00"); @@ -92,11 +92,11 @@ public void testInstantStringInputWithNull() throws Exception { Instant.of((String)null); } - @Test(groups = { "instant-tests" }, expectedExceptions = IllegalStateException.class) + @Test(groups = { "instant-tests" }, expectedExceptions = NullPointerException.class) public void testInstantWithNullZonedDateTime() throws Exception { Instant.of((ZonedDateTime)null); } - + @Test(groups = { "instant-tests" }) public void testInstantPrecise() throws Exception { assertTrue(Instant.of("2018-12-31T20:00:00.112-04:00").getValue() @@ -117,7 +117,7 @@ public void testDateWithValidStringInputs() throws Exception{ assertTrue(Date.of("2018-12").isPartial()); // Partial date with year only assertTrue(Date.of("2018").isPartial()); - } + } @Test(groups = { "date-tests" }) public void testDateWithValidTemporalAccessor() throws Exception{ @@ -148,7 +148,7 @@ public void testDateWithNullString() throws Exception{ Date.of((String)null); } - @Test(groups = { "date-tests" }, expectedExceptions = IllegalStateException.class) + @Test(groups = { "date-tests" }, expectedExceptions = NullPointerException.class) public void testDateWithNullTemporalAccessor() throws Exception{ Date.of((TemporalAccessor)null); } @@ -173,7 +173,7 @@ public void testDateTimeWithValidInputs() throws Exception{ assertTrue(DateTime.of("2018-12").isPartial()); assertTrue(DateTime.of("2018").isPartial()); } - + @Test(groups = { "datetime-tests" }, expectedExceptions = DateTimeParseException.class) public void testDateTimeStringInputWithoutTimeZone() throws Exception { DateTime.of("2018-12-31T20:00:08.112"); @@ -198,7 +198,7 @@ public void testDateTimeStringInputWithWrongSeperator() throws Exception { public void testDateTimeStringInputWithShortDateValue() throws Exception { DateTime.of("2018-2-3T20:00:00-04:00"); } - + @Test(groups = { "datetime-tests" }, expectedExceptions = DateTimeParseException.class) public void testDateTimeStringInputWithIlegalChars() throws Exception { DateTime.of("2018-aa-bbT20:00:00-04:00"); @@ -209,7 +209,7 @@ public void testDateTimeWithNullString() throws Exception { DateTime.of((String)null); } - @Test(groups = { "datetime-tests" }, expectedExceptions = IllegalStateException.class) + @Test(groups = { "datetime-tests" }, expectedExceptions = NullPointerException.class) public void testDateTimeWithNullTemporalAccessor() throws Exception { DateTime.of((TemporalAccessor)null); } @@ -290,7 +290,7 @@ public void testTimeWithNullString() throws Exception { Time.of((String)null); } - @Test(groups = { "time-tests" }, expectedExceptions = IllegalStateException.class) + @Test(groups = { "time-tests" }, expectedExceptions = NullPointerException.class) public void testTimeWithNullLocalTime() throws Exception { Time.of((LocalTime)null); } diff --git a/fhir-model/src/test/java/com/ibm/fhir/model/util/test/ValidationSupportTest.java b/fhir-model/src/test/java/com/ibm/fhir/model/util/test/ValidationSupportTest.java index e0c5c12f2e4..1f18a91c09b 100644 --- a/fhir-model/src/test/java/com/ibm/fhir/model/util/test/ValidationSupportTest.java +++ b/fhir-model/src/test/java/com/ibm/fhir/model/util/test/ValidationSupportTest.java @@ -49,7 +49,7 @@ public void testCheckValueSetBindingCodeNotValid1() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingCodeNotValid2() { try { @@ -57,7 +57,7 @@ public void testCheckValueSetBindingCodeNotValid2() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingCodesValid() { ValidationSupport.checkValueSetBinding(Arrays.asList(Code.of("code1"), Code.of("code2")), "elementName", "valueSetUrl", null, "code1", "code2"); @@ -93,7 +93,7 @@ public void testCheckValueSetBindingStringNotValid1() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingStringNotValid2() { try { @@ -101,7 +101,7 @@ public void testCheckValueSetBindingStringNotValid2() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingStringsValid() { ValidationSupport.checkValueSetBinding(Arrays.asList(com.ibm.fhir.model.type.String.of("code1"), com.ibm.fhir.model.type.String.of("code2")), "elementName", "valueSetUrl", null, "code1", "code2"); @@ -137,7 +137,7 @@ public void testCheckValueSetBindingUriNotValid1() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingUriNotValid2() { try { @@ -145,7 +145,7 @@ public void testCheckValueSetBindingUriNotValid2() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingUrisValid() { ValidationSupport.checkValueSetBinding(Arrays.asList(Uri.of("code1"), Uri.of("code2")), "elementName", "valueSetUrl", null, "code1", "code2"); @@ -385,7 +385,7 @@ public void testCheckValueSetBindingCodeableConceptsNotValid() { } catch (IllegalStateException e) { } } - + @Test public void testCheckValueSetBindingCodeableConceptLenientValid1() { FHIRModelConfig.setProperty(FHIRModelConfig.PROPERTY_EXTENDED_CODEABLE_CONCEPT_VALIDATION, false); @@ -458,7 +458,7 @@ public void testCheckValueSetBindingLanguageCodeNotValid1() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodeNotValid2() { try { @@ -466,7 +466,7 @@ public void testCheckValueSetBindingLanguageCodeNotValid2() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodeNotValid3() { try { @@ -474,7 +474,7 @@ public void testCheckValueSetBindingLanguageCodeNotValid3() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodeNotValid4() { try { @@ -482,7 +482,7 @@ public void testCheckValueSetBindingLanguageCodeNotValid4() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodeNotValid5() { try { @@ -498,12 +498,12 @@ public void testCheckValueSetBindingLanguageCodeNotValid6() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodesValid() { ValidationSupport.checkValueSetBinding(Collections.singletonList(Code.of("ar")), "elementName", ValidationSupport.ALL_LANG_VALUE_SET_URL, null); } - + @Test public void testCheckValueSetBindingLanguageCodesNotValid() { try { @@ -535,15 +535,15 @@ public void testCheckValueSetBindingLanguageCodingNotValid1() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingNotValid2() { - try { + try { ValidationSupport.checkValueSetBinding(Coding.builder().system(Uri.of(ValidationSupport.BCP_47_URN)).code(Code.of("")).build(), "elementName", ValidationSupport.ALL_LANG_VALUE_SET_URL, null); fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingNotValid3() { try { @@ -551,7 +551,7 @@ public void testCheckValueSetBindingLanguageCodingNotValid3() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingNotValid4() { try { @@ -559,7 +559,7 @@ public void testCheckValueSetBindingLanguageCodingNotValid4() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingNotValid5() { try { @@ -567,7 +567,7 @@ public void testCheckValueSetBindingLanguageCodingNotValid5() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingNotValid6() { try { @@ -575,7 +575,7 @@ public void testCheckValueSetBindingLanguageCodingNotValid6() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingNotValid7() { try { @@ -583,7 +583,7 @@ public void testCheckValueSetBindingLanguageCodingNotValid7() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingNotValid8() { try { @@ -599,7 +599,7 @@ public void testCheckValueSetBindingLanguageCodingNotValid9() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodingsValid() { ValidationSupport.checkValueSetBinding(Collections.singletonList(Coding.builder().system(Uri.of(ValidationSupport.BCP_47_URN)).code(Code.of("ar")).build()), "elementName", ValidationSupport.ALL_LANG_VALUE_SET_URL, null); @@ -610,7 +610,7 @@ public void testCheckValueSetBindingLanguageCodingsNotValid() { try { ValidationSupport.checkValueSetBinding(Arrays.asList(Coding.builder().code(Code.of("ar")).build(), Coding.builder().system(Uri.of("invalidSystem")).code(Code.of("ar")).build()), "elementName", ValidationSupport.ALL_LANG_VALUE_SET_URL, null); - fail(); + fail(); } catch (IllegalStateException e) {} } @@ -669,7 +669,7 @@ public void testCheckValueSetBindingLanguageCodeableConceptNotValid3() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingLanguageCodeableConceptsValid() { ValidationSupport.checkValueSetBinding(Collections.singletonList(CodeableConcept.builder().coding( @@ -687,7 +687,7 @@ public void testCheckValueSetBindingLanguageCodeableConceptsNotValid() { fail(); } catch (IllegalStateException e) {} } - + @Test public void testCheckValueSetBindingUcumCodeValid1() { ValidationSupport.checkValueSetBinding((Code)null, "elementName", ValidationSupport.UCUM_UNITS_VALUE_SET_URL, null); @@ -716,7 +716,7 @@ public void testCheckValueSetBindingUcumCodeValid5() { @Test public void testCheckValueSetBindingUcumCodeNotValid1() { try { - ValidationSupport.checkValueSetBinding(Code.of(null), "elementName", ValidationSupport.UCUM_UNITS_VALUE_SET_URL, null); + ValidationSupport.checkValueSetBinding(Code.builder().build(), "elementName", ValidationSupport.UCUM_UNITS_VALUE_SET_URL, null); fail(); } catch (IllegalStateException e) { } @@ -832,7 +832,7 @@ public void testCheckValueSetBindingUcumCodingNotValid3() { @Test public void testCheckValueSetBindingUcumCodingNotValid4() { try { - ValidationSupport.checkValueSetBinding(Coding.builder().system(Uri.of(null)).code(Code.of("mg/mmol")).build(), "elementName", ValidationSupport.UCUM_UNITS_VALUE_SET_URL, null); + ValidationSupport.checkValueSetBinding(Coding.builder().system(Uri.builder().build()).code(Code.of("mg/mmol")).build(), "elementName", ValidationSupport.UCUM_UNITS_VALUE_SET_URL, null); fail(); } catch (IllegalStateException e) { } @@ -841,7 +841,7 @@ public void testCheckValueSetBindingUcumCodingNotValid4() { @Test public void testCheckValueSetBindingUcumCodingNotValid5() { try { - ValidationSupport.checkValueSetBinding(Coding.builder().system(Uri.of(ValidationSupport.UCUM_CODE_SYSTEM_URL)).code(Code.of(null)).build(), "elementName", ValidationSupport.UCUM_UNITS_VALUE_SET_URL, null); + ValidationSupport.checkValueSetBinding(Coding.builder().system(Uri.of(ValidationSupport.UCUM_CODE_SYSTEM_URL)).code(Code.builder().build()).build(), "elementName", ValidationSupport.UCUM_UNITS_VALUE_SET_URL, null); fail(); } catch (IllegalStateException e) { } @@ -967,5 +967,5 @@ public void testCheckValueSetBindingUcumCodeableConceptsNotValid() { } catch (IllegalStateException e) { } } - + } diff --git a/fhir-tools/src/main/java/com/ibm/fhir/tools/CodeGenerator.java b/fhir-tools/src/main/java/com/ibm/fhir/tools/CodeGenerator.java index 7fcac742ceb..171b5d3caea 100644 --- a/fhir-tools/src/main/java/com/ibm/fhir/tools/CodeGenerator.java +++ b/fhir-tools/src/main/java/com/ibm/fhir/tools/CodeGenerator.java @@ -1755,101 +1755,205 @@ private void generateFactoryMethods(JsonObject structureDefinition, CodeBuilder String className = titleCase(structureDefinition.getString("name")); if (isDate(structureDefinition) || isDateTime(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a TemporalAccessor") + .javadoc("") + .javadocParam("value", "A TemporalAccessor, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("TemporalAccessor value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String value that can be parsed by {@link #PARSER_FORMATTER}, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isDateTime(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating a " + className + " that represents the current DateTime") + .javadocEnd(); cb.method(mods("public", "static"), className, "now") ._return(className + ".builder().value(ZonedDateTime.now()).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating a " + className + " that represents the current DateTime in the passed time zone") + .javadoc("") + .javadocParam("offset", "The ZoneOffset for the desired time zone, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "now", params("ZoneOffset offset")) + .invoke("Objects", "requireNonNull", args("offset","\"offset\"")) ._return(className + ".builder().value(ZonedDateTime.now(offset)).build()") .end().newLine(); } if (isInstant(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a ZonedDateTime") + .javadoc("") + .javadocParam("value", "A ZonedDateTime, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("ZonedDateTime value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String value that can be parsed by {@link #PARSER_FORMATTER}, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating a " + className + " that represents the current Instant") + .javadocEnd(); cb.method(mods("public", "static"), className, "now") ._return(className + ".builder().value(ZonedDateTime.now()).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating a " + className + " that represents the current Instant in the passed time zone") + .javadoc("") + .javadocParam("offset", "the ZoneOffset for the desired time zone, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "now", params("ZoneOffset offset")) + .invoke("Objects", "requireNonNull", args("offset","\"offset\"")) ._return(className + ".builder().value(ZonedDateTime.now(offset)).build()") .end().newLine(); } if (isTime(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a LocalTime") + .javadoc("") + .javadocParam("value", "A LocalTime, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("LocalTime value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String value that can be parsed by {@link #PARSER_FORMATTER}, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isBoolean(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.Boolean") + .javadoc("") + .javadocParam("value", "A java.lang.Boolean, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.Boolean value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String value that can be parsed into a java.lang.Boolean, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isDecimal(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a BigDecimal") + .javadoc("") + .javadocParam("value", "A BigDecimal, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("BigDecimal value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a Number") + .javadoc("") + .javadocParam("value", "A Number, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("Number value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value.toString()).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String value that can be parsed into a BigDecimal, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isInteger(structureDefinition) || isIntegerSubtype(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.Integer") + .javadoc("") + .javadocParam("value", "A java.lang.Integer, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.Integer value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String value that can be parsed into a java.lang.Integer, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isString(structureDefinition) || isStringSubtype(structureDefinition) || isUri(structureDefinition) || isUriSubtype(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String, not null") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isCanonical(structureDefinition)) { -// StringBuilder value = new StringBuilder(url); -// if (version != null && !version.isEmpty()) { -// value.append("|" + version); -// } -// return of(value.toString()); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String uri and version") + .javadoc("") + .javadocParam("value", "A java.lang.String for the uri portion of the canonical reference, not null") + .javadocParam("value", "A java.lang.String for the version portion of the canonical reference") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String uri", "java.lang.String version")) + .invoke("Objects", "requireNonNull", args("uri","\"uri\"")) .assign("StringBuilder value", "new StringBuilder(uri)") ._if("version != null && !version.isEmpty()") .invoke("value", "append", args("'|'")) @@ -1858,7 +1962,15 @@ private void generateFactoryMethods(JsonObject structureDefinition, CodeBuilder ._return(className + ".builder().value(value.toString()).build()") .end().newLine(); + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String uri, version, and fragment") + .javadoc("") + .javadocParam("value", "A java.lang.String for the uri portion of the canonical reference, not null") + .javadocParam("value", "A java.lang.String for the version portion of the canonical reference") + .javadocParam("value", "A java.lang.String for the fragment portion of the canonical reference") + .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String uri", "java.lang.String version", "java.lang.String fragment")) + .invoke("Objects", "requireNonNull", args("uri","\"uri\"")) .assign("StringBuilder value", "new StringBuilder(uri)") ._if("version != null && !version.isEmpty()") .invoke("value", "append", args("'|'")) @@ -1873,7 +1985,13 @@ private void generateFactoryMethods(JsonObject structureDefinition, CodeBuilder } if (isString(structureDefinition) || isStringSubtype(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String, not null") + .javadocEnd(); cb.method(mods("public", "static"), "String", "string", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } @@ -1882,36 +2000,56 @@ private void generateFactoryMethods(JsonObject structureDefinition, CodeBuilder cb.javadocStart() .javadoc("Factory method for creating Base64Binary objects from a byte array; this array should be the actual value.") .javadoc("") - .javadocParam("value", "The byte array of to-be-encoded content") + .javadocParam("value", "The byte array of to-be-encoded content, not null") .javadocEnd(); cb.method(mods("public", "static"), "Base64Binary", "of", params("byte[] value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); cb.javadocStart() .javadoc("Factory method for creating Base64Binary objects from a Base64 encoded value.") .javadoc("") - .javadocParam("value", "The Base64 encoded string") + .javadocParam("value", "The Base64 encoded string, not null") .javadocEnd(); cb.method(mods("public", "static"), "Base64Binary", "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isUri(structureDefinition) || isUriSubtype(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String that can be parsed into a valid FHIR uri value, not null") + .javadocEnd(); cb.method(mods("public", "static"), "Uri", "uri", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isInteger(structureDefinition) || isIntegerSubtype(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String that can be parsed into a java.lang.Integer, not null") + .javadocEnd(); cb.method(mods("public", "static"), "Integer", "integer", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); } if (isCode(structureDefinition)) { + cb.javadocStart() + .javadoc("Factory method for creating " + className + " objects from a java.lang.String") + .javadoc("") + .javadocParam("value", "A java.lang.String that can be parsed into a valid FHIR code value, not null") + .javadocEnd(); cb.method(mods("public", "static"), "Code", "code", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return("Code.builder().value(value).build()") .end().newLine(); } @@ -1920,18 +2058,20 @@ private void generateFactoryMethods(JsonObject structureDefinition, CodeBuilder cb.javadocStart() .javadoc("Factory method for creating Xhtml objects from an XHTML java.lang.String") .javadoc("") - .javadocParam("value", "A java.lang.String with valid XHTML content") + .javadocParam("value", "A java.lang.String with valid XHTML content, not null") .javadocEnd(); cb.method(mods("public", "static"), className, "of", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return(className + ".builder().value(value).build()") .end().newLine(); cb.javadocStart() .javadoc("Factory method for creating Xhtml objects from an XHTML java.lang.String") .javadoc("") - .javadocParam("value", "A java.lang.String with valid XHTML content") + .javadocParam("value", "A java.lang.String with valid XHTML content, not null") .javadocEnd(); cb.method(mods("public", "static"), "Xhtml", "xhtml", params("java.lang.String value")) + .invoke("Objects", "requireNonNull", args("value","\"value\"")) ._return("Xhtml.builder().value(value).build()") .end().newLine(); @@ -1941,9 +2081,10 @@ private void generateFactoryMethods(JsonObject structureDefinition, CodeBuilder .javadoc("

This method will automatically encode the passed string for use within XHTML,", false) .javadoc("then wrap it in an XHTML {@code

} element with a namespace of {@code http://www.w3.org/1999/xhtml}", false) .javadoc("") - .javadocParam("plainText", "The text to encode and wrap for use within a Narrative") + .javadocParam("plainText", "The text to encode and wrap for use within a Narrative, not null") .javadocEnd(); cb.method(mods("public", "static"), "Xhtml", "from", params("java.lang.String plainText")) + .invoke("Objects", "requireNonNull", args("plainText","\"plainText\"")) ._return("Xhtml.builder().value(DIV_OPEN + Encode.forHtmlContent(plainText) + DIV_CLOSE).build()") .end().newLine(); }