- * A {@code JsonObject} can be produced by a {@link Json#parse(String)}.
- *
- * Alternatively, {@link #of(Map)} can be used to obtain a {@code JsonObject}.
- * Implementations of {@code JsonObject} cannot be created from sources that
- * contain duplicate member names. If duplicate names appear during
- * a {@link Json#parse(String)}, a {@code JsonParseException} is thrown.
- *
- * @since 99
- */
+/// The interface that represents JSON object.
+///
+/// A {@code JsonObject} can be produced by a {@link Json#parse(String)}.
+///
+/// Alternatively, {@link #of(Map)} can be used to obtain a {@code JsonObject}.
+/// Implementations of {@code JsonObject} cannot be created from sources that
+/// contain duplicate member names. If duplicate names appear during
+/// a {@link Json#parse(String)}, a {@code JsonParseException} is thrown.
+///
+/// @since 99
@PreviewFeature(feature = PreviewFeature.Feature.JSON)
public non-sealed interface JsonObject extends JsonValue {
- /**
- * {@return an unmodifiable map of the {@code String} to {@code JsonValue}
- * members in this {@code JsonObject}}
- */
+ /// {@return an unmodifiable map of the {@code String} to {@code JsonValue}
+ /// members in this {@code JsonObject}}
Map
- * A {@code JsonBoolean} can be produced by {@link Json#parse(String)}. - *
Alternatively, {@link #of(boolean)} can be used to - * obtain a {@code JsonBoolean}. - * - * @since 99 - */ +/// The interface that represents JSON boolean. +/// +/// A {@code JsonBoolean} can be produced by {@link Json#parse(String)}. +/// Alternatively, {@link #of(boolean)} can be used to +/// obtain a {@code JsonBoolean}. +/// +/// @since 99 public non-sealed interface JsonBoolean extends JsonValue { - /** - * {@return the {@code boolean} value represented by this - * {@code JsonBoolean}} - */ + /// {@return the {@code boolean} value represented by this + /// {@code JsonBoolean}} boolean value(); - /** - * {@return the {@code JsonBoolean} created from the given - * {@code boolean}} - * - * @param src the given {@code boolean}. - */ + /// {@return the {@code JsonBoolean} created from the given + /// {@code boolean}} + /// + /// @param src the given {@code boolean}. static JsonBoolean of(boolean src) { return src ? JsonBooleanImpl.TRUE : JsonBooleanImpl.FALSE; } - /** - * {@return {@code true} if the given object is also a {@code JsonBoolean} - * and the two {@code JsonBoolean}s represent the same boolean value} Two - * {@code JsonBoolean}s {@code jb1} and {@code jb2} represent the same - * boolean values if {@code jb1.value().equals(jb2.value())}. - * - * @see #value() - */ + /// {@return {@code true} if the given object is also a {@code JsonBoolean} + /// and the two {@code JsonBoolean}s represent the same boolean value} Two + /// {@code JsonBoolean}s {@code jb1} and {@code jb2} represent the same + /// boolean values if {@code jb1.value().equals(jb2.value())}. + /// + /// @see #value() @Override boolean equals(Object obj); - /** - * {@return the hash code value for this {@code JsonBoolean}} The hash code value - * of a {@code JsonBoolean} is derived from the hash code of {@code JsonBoolean}'s - * {@link #value()}. Thus, for two {@code JsonBooleans}s {@code jb1} and {@code jb2}, - * {@code jb1.equals(jb2)} implies that {@code jb1.hashCode() == jb2.hashCode()} - * as required by the general contract of {@link Object#hashCode}. - * - * @see #value() - */ + /// {@return the hash code value for this {@code JsonBoolean}} The hash code value + /// of a {@code JsonBoolean} is derived from the hash code of {@code JsonBoolean}'s + /// {@link #value()}. Thus, for two {@code JsonBooleans}s {@code jb1} and {@code jb2}, + /// {@code jb1.equals(jb2)} implies that {@code jb1.hashCode() == jb2.hashCode()} + /// as required by the general contract of {@link Object#hashCode}. + /// + /// @see #value() @Override int hashCode(); } diff --git a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNull.java b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNull.java index 92f3949..90e2411 100644 --- a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNull.java +++ b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNull.java @@ -27,32 +27,24 @@ import jdk.sandbox.internal.util.json.JsonNullImpl; -/** - * The interface that represents JSON null. - *
- * A {@code JsonNull} can be produced by {@link Json#parse(String)}. - *
Alternatively, {@link #of()} can be used to obtain a {@code JsonNull}. - * - * @since 99 - */ +/// The interface that represents JSON null. +/// +/// A {@code JsonNull} can be produced by {@link Json#parse(String)}. +/// Alternatively, {@link #of()} can be used to obtain a {@code JsonNull}. +/// +/// @since 99 public non-sealed interface JsonNull extends JsonValue { - /** - * {@return a {@code JsonNull}} - */ + /// {@return a {@code JsonNull}} static JsonNull of() { return JsonNullImpl.NULL; } - /** - * {@return true if the given {@code obj} is a {@code JsonNull}} - */ + /// {@return true if the given {@code obj} is a {@code JsonNull}} @Override boolean equals(Object obj); - /** - * {@return the hash code value of this {@code JsonNull}} - */ + /// {@return the hash code value of this {@code JsonNull}} @Override int hashCode(); } diff --git a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNumber.java b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNumber.java index 6186c86..9e5fe8d 100644 --- a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNumber.java +++ b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonNumber.java @@ -30,174 +30,154 @@ import jdk.sandbox.internal.util.json.JsonNumberImpl; -/** - * The interface that represents JSON number, an arbitrary-precision - * number represented in base 10 using decimal digits. - *
- * A {@code JsonNumber} can be produced by {@link Json#parse(String)}. - * Alternatively, {@link #of(double)} and its overloads can be used to obtain - * a {@code JsonNumber} from a {@code Number}. - * When a JSON number is parsed, a {@code JsonNumber} object is created - * as long as the parsed value adheres to the JSON number - * - * syntax. The value of the {@code JsonNumber} - * can be retrieved from {@link #toString()} as the string representation - * from which the JSON number is originally parsed, with - * {@link #toNumber()} as a {@code Number} instance, or with - * {@link #toBigDecimal()}. - * - * @spec https://datatracker.ietf.org/doc/html/rfc8259#section-6 RFC 8259: - * The JavaScript Object Notation (JSON) Data Interchange Format - Numbers - * @since 99 - */ +/// The interface that represents JSON number, an arbitrary-precision +/// number represented in base 10 using decimal digits. +/// +/// A {@code JsonNumber} can be produced by {@link Json#parse(String)}. +/// Alternatively, {@link #of(double)} and its overloads can be used to obtain +/// a {@code JsonNumber} from a {@code Number}. +/// When a JSON number is parsed, a {@code JsonNumber} object is created +/// as long as the parsed value adheres to the JSON number +/// [syntax](https://datatracker.ietf.org/doc/html/rfc8259#section-6). +/// The value of the {@code JsonNumber} +/// can be retrieved from {@link #toString()} as the string representation +/// from which the JSON number is originally parsed, with +/// {@link #toNumber()} as a {@code Number} instance, or with +/// {@link #toBigDecimal()}. +/// +/// @spec https://datatracker.ietf.org/doc/html/rfc8259#section-6 RFC 8259: +/// The JavaScript Object Notation (JSON) Data Interchange Format - Numbers +/// @since 99 public non-sealed interface JsonNumber extends JsonValue { - /** - * {@return the {@code Number} parsed or translated from the - * {@link #toString string representation} of this {@code JsonNumber}} - *
- * This method operates on the string representation and depending on that - * representation computes and returns an instance of {@code Long}, {@code BigInteger}, - * {@code Double}, or {@code BigDecimal}. - *
- * If the string representation is the decimal string representation of - * a {@code long} value, parsable by {@link Long#parseLong(String)}, - * then that {@code long} value is returned in its boxed form as {@code Long}. - * Otherwise, if the string representation is the decimal string representation of a - * {@code BigInteger}, translatable by {@link BigInteger#BigInteger(String)}, - * then that {@code BigInteger} is returned. - * Otherwise, if the string representation is the decimal string representation of - * a {@code double} value, parsable by {@link Double#parseDouble(String)}, - * and the {@code double} value is not {@link Double#isInfinite() infinite}, then that - * {@code double} value is returned in its boxed form as {@code Double}. - * Otherwise, and in all other cases, the string representation is the decimal string - * representation of a {@code BigDecimal}, translatable by - * {@link BigDecimal#BigDecimal(String)}, and that {@code BigDecimal} is - * returned. - *
- * The computation may not preserve all information in the string representation. - * In all of the above cases one or more leading zero digits are not preserved. - * In the third case, returning {@code Double}, decimal to binary conversion may lose - * decimal precision, and will not preserve one or more trailing zero digits in the fraction - * part. - * - * @apiNote - * Pattern matching can be used to match against {@code Long}, - * {@code Double}, {@code BigInteger}, or {@code BigDecimal} reference - * types. For example: - * {@snippet lang=java: - * switch(jsonNumber.toNumber()) { - * case Long l -> { ... } - * case Double d -> { ... } - * case BigInteger bi -> { ... } - * case BigDecimal bd -> { ... } - * default -> { } // should not happen - * } - *} - * @throws NumberFormatException if the {@code Number} cannot be parsed or translated from the string representation - * @see #toBigDecimal() - * @see #toString() - */ + /// {@return the {@code Number} parsed or translated from the + /// {@link #toString string representation} of this {@code JsonNumber}} + /// + /// This method operates on the string representation and depending on that + /// representation computes and returns an instance of {@code Long}, {@code BigInteger}, + /// {@code Double}, or {@code BigDecimal}. + /// + /// If the string representation is the decimal string representation of + /// a {@code long} value, parsable by {@link Long#parseLong(String)}, + /// then that {@code long} value is returned in its boxed form as {@code Long}. + /// Otherwise, if the string representation is the decimal string representation of a + /// {@code BigInteger}, translatable by {@link BigInteger#BigInteger(String)}, + /// then that {@code BigInteger} is returned. + /// Otherwise, if the string representation is the decimal string representation of + /// a {@code double} value, parsable by {@link Double#parseDouble(String)}, + /// and the {@code double} value is not {@link Double#isInfinite() infinite}, then that + /// {@code double} value is returned in its boxed form as {@code Double}. + /// Otherwise, and in all other cases, the string representation is the decimal string + /// representation of a {@code BigDecimal}, translatable by + /// {@link BigDecimal#BigDecimal(String)}, and that {@code BigDecimal} is + /// returned. + /// + /// The computation may not preserve all information in the string representation. + /// In all of the above cases one or more leading zero digits are not preserved. + /// In the third case, returning {@code Double}, decimal to binary conversion may lose + /// decimal precision, and will not preserve one or more trailing zero digits in the fraction + /// part. + /// + /// @apiNote + /// Pattern matching can be used to match against {@code Long}, + /// {@code Double}, {@code BigInteger}, or {@code BigDecimal} reference + /// types. For example: + /// {@snippet lang=java: + /// switch(jsonNumber.toNumber()) { + /// case Long l -> { ... } + /// case Double d -> { ... } + /// case BigInteger bi -> { ... } + /// case BigDecimal bd -> { ... } + /// default -> { } // should not happen + /// } + ///} + /// @throws NumberFormatException if the {@code Number} cannot be parsed or translated from the string representation + /// @see #toBigDecimal() + /// @see #toString() Number toNumber(); - /** - * {@return the {@code BigDecimal} translated from the - * {@link #toString string representation} of this {@code JsonNumber}} - *
- * The string representation is the decimal string representation of a - * {@code BigDecimal}, translatable by {@link BigDecimal#BigDecimal(String)}, - * and that {@code BigDecimal} is returned. - *
- * The translation may not preserve all information in the string representation. - * The sign is not preserved for the decimal string representation {@code -0.0}. One or more - * leading zero digits are not preserved. - * - * @throws NumberFormatException if the {@code BigDecimal} cannot be translated from the string representation - */ + /// {@return the {@code BigDecimal} translated from the + /// {@link #toString string representation} of this {@code JsonNumber}} + /// + /// The string representation is the decimal string representation of a + /// {@code BigDecimal}, translatable by {@link BigDecimal#BigDecimal(String)}, + /// and that {@code BigDecimal} is returned. + /// + /// The translation may not preserve all information in the string representation. + /// The sign is not preserved for the decimal string representation {@code -0.0}. One or more + /// leading zero digits are not preserved. + /// + /// @throws NumberFormatException if the {@code BigDecimal} cannot be translated from the string representation BigDecimal toBigDecimal(); - /** - * Creates a JSON number whose string representation is the - * decimal string representation of the given {@code double} value, - * produced by applying the value to {@link Double#toString(double)}. - * - * @param num the given {@code double} value. - * @return a JSON number created from a {@code double} value - * @throws IllegalArgumentException if the given {@code double} value - * is {@link Double#isNaN() NaN} or is {@link Double#isInfinite() infinite}. - */ + /// Creates a JSON number whose string representation is the + /// decimal string representation of the given {@code double} value, + /// produced by applying the value to {@link Double#toString(double)}. + /// + /// @param num the given {@code double} value. + /// @return a JSON number created from a {@code double} value + /// @throws IllegalArgumentException if the given {@code double} value + /// is {@link Double#isNaN() NaN} or is {@link Double#isInfinite() infinite}. static JsonNumber of(double num) { // non-integral types return new JsonNumberImpl(num); } - /** - * Creates a JSON number whose string representation is the - * decimal string representation of the given {@code long} value, - * produced by applying the value to {@link Long#toString(long)}. - * - * @param num the given {@code long} value. - * @return a JSON number created from a {@code long} value - */ + /// Creates a JSON number whose string representation is the + /// decimal string representation of the given {@code long} value, + /// produced by applying the value to {@link Long#toString(long)}. + /// + /// @param num the given {@code long} value. + /// @return a JSON number created from a {@code long} value static JsonNumber of(long num) { // integral types return new JsonNumberImpl(num); } - /** - * Creates a JSON number whose string representation is the - * string representation of the given {@code BigInteger} value. - * - * @param num the given {@code BigInteger} value. - * @return a JSON number created from a {@code BigInteger} value - */ + /// Creates a JSON number whose string representation is the + /// string representation of the given {@code BigInteger} value. + /// + /// @param num the given {@code BigInteger} value. + /// @return a JSON number created from a {@code BigInteger} value static JsonNumber of(BigInteger num) { return new JsonNumberImpl(num); } - /** - * Creates a JSON number whose string representation is the - * string representation of the given {@code BigDecimal} value. - * - * @param num the given {@code BigDecimal} value. - * @return a JSON number created from a {@code BigDecimal} value - */ + /// Creates a JSON number whose string representation is the + /// string representation of the given {@code BigDecimal} value. + /// + /// @param num the given {@code BigDecimal} value. + /// @return a JSON number created from a {@code BigDecimal} value static JsonNumber of(BigDecimal num) { return new JsonNumberImpl(num); } - /** - * {@return the decimal string representation of this {@code JsonNumber}} - * - * If this {@code JsonNumber} is created by parsing a JSON number in a JSON document, - * it preserves the string representation in the document, regardless of its - * precision or range. For example, a JSON number like - * {@code 3.141592653589793238462643383279} in the JSON document will be - * returned exactly as it appears. - * If this {@code JsonNumber} is created via one of the factory methods, - * such as {@link JsonNumber#of(double)}, then the string representation is - * specified by the factory method. - */ + /// {@return the decimal string representation of this {@code JsonNumber}} + /// + /// If this {@code JsonNumber} is created by parsing a JSON number in a JSON document, + /// it preserves the string representation in the document, regardless of its + /// precision or range. For example, a JSON number like + /// {@code 3.141592653589793238462643383279} in the JSON document will be + /// returned exactly as it appears. + /// If this {@code JsonNumber} is created via one of the factory methods, + /// such as {@link JsonNumber#of(double)}, then the string representation is + /// specified by the factory method. @Override String toString(); - /** - * {@return true if the given {@code obj} is equal to this {@code JsonNumber}} - * The comparison is based on the string representation of this {@code JsonNumber}, - * ignoring the case. - * - * @see #toString() - */ + /// {@return true if the given {@code obj} is equal to this {@code JsonNumber}} + /// The comparison is based on the string representation of this {@code JsonNumber}, + /// ignoring the case. + /// + /// @see #toString() @Override boolean equals(Object obj); - /** - * {@return the hash code value of this {@code JsonNumber}} The returned hash code - * is derived from the string representation of this {@code JsonNumber}, - * ignoring the case. - * - * @see #toString() - */ + /// {@return the hash code value of this {@code JsonNumber}} The returned hash code + /// is derived from the string representation of this {@code JsonNumber}, + /// ignoring the case. + /// + /// @see #toString() @Override int hashCode(); } diff --git a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonParseException.java b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonParseException.java index 18dbb15..88c64a5 100644 --- a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonParseException.java +++ b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonParseException.java @@ -28,51 +28,39 @@ import java.io.Serial; -/** - * Signals that an error has been detected while parsing the - * JSON document. - * - * @since 99 - */ +/// Signals that an error has been detected while parsing the +/// JSON document. +/// +/// @since 99 public class JsonParseException extends RuntimeException { @Serial private static final long serialVersionUID = 7022545379651073390L; - /** - * Position of the error row in the document - * @serial - */ + /// Position of the error row in the document + /// @serial private final int row; - /** - * Position of the error column in the document - * @serial - */ + /// Position of the error column in the document + /// @serial private final int col; - /** - * Constructs a JsonParseException with the specified detail message. - * @param message the detail message - * @param row the row of the error on parsing the document - * @param col the column of the error on parsing the document - */ + /// Constructs a JsonParseException with the specified detail message. + /// @param message the detail message + /// @param row the row of the error on parsing the document + /// @param col the column of the error on parsing the document public JsonParseException(String message, int row, int col) { super(message); this.row = row; this.col = col; } - /** - * {@return the row of the error on parsing the document} - */ + /// {@return the row of the error on parsing the document} public int getErrorRow() { return row; } - /** - * {@return the column of the error on parsing the document} - */ + /// {@return the column of the error on parsing the document} public int getErrorColumn() { return col; } diff --git a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonString.java b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonString.java index 57b061f..234efdc 100644 --- a/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonString.java +++ b/json-java21/src/main/java/jdk/sandbox/java/util/json/JsonString.java @@ -29,78 +29,67 @@ import jdk.sandbox.internal.util.json.JsonStringImpl; -/** - * The interface that represents a JSON string. - *
- * A {@code JsonString} can be produced by a {@link Json#parse(String)}. - * Within a valid JSON String, any character may be escaped using either a - * two-character escape sequence (if applicable) or a Unicode escape sequence. - * Quotation mark (U+0022), reverse solidus (U+005C), and the control characters - * (U+0000 through U+001F) must be escaped. - *
Alternatively, {@link #of(String)} can be used to obtain a {@code JsonString} - * directly from a {@code String}. The following expressions are all equivalent, - * {@snippet lang="java" : - * Json.parse("\"foo\\t\""); - * Json.parse("\"foo\\u0009\""); - * JsonString.of("foo\t"); - * } - * - * @spec https://datatracker.ietf.org/doc/html/rfc8259#section-7 RFC 8259: - * The JavaScript Object Notation (JSON) Data Interchange Format - Strings - * @since 99 - */ +/// The interface that represents a JSON string. +/// +/// A {@code JsonString} can be produced by a {@link Json#parse(String)}. +/// Within a valid JSON String, any character may be escaped using either a +/// two-character escape sequence (if applicable) or a Unicode escape sequence. +/// Quotation mark (U+0022), reverse solidus (U+005C), and the control characters +/// (U+0000 through U+001F) must be escaped. +/// +/// Alternatively, {@link #of(String)} can be used to obtain a {@code JsonString} +/// directly from a {@code String}. The following expressions are all equivalent, +/// {@snippet lang="java" : +/// Json.parse("\"foo\\t\""); +/// Json.parse("\"foo\\u0009\""); +/// JsonString.of("foo\t"); +/// } +/// +/// @spec https://datatracker.ietf.org/doc/html/rfc8259#section-7 RFC 8259: +/// The JavaScript Object Notation (JSON) Data Interchange Format - Strings +/// @since 99 public non-sealed interface JsonString extends JsonValue { - /** - * {@return the {@code JsonString} created from the given - * {@code String}} - * - * @param value the given {@code String} used as the {@code value} of this - * {@code JsonString}. Non-null. - * @throws NullPointerException if {@code value} is {@code null} - */ + /// {@return the {@code JsonString} created from the given + /// {@code String}} + /// + /// @param value the given {@code String} used as the {@code value} of this + /// {@code JsonString}. Non-null. + /// @throws NullPointerException if {@code value} is {@code null} static JsonString of(String value) { Objects.requireNonNull(value); return new JsonStringImpl(value); } - /** - * {@return the JSON {@code String} represented by this {@code JsonString}} - * If this {@code JsonString} was created by parsing a JSON document, it - * preserves the text representation of the corresponding JSON String. Otherwise, - * the {@code value} is escaped to produce the JSON {@code String}. - * - * @see #value() - */ + /// {@return the JSON {@code String} represented by this {@code JsonString}} + /// If this {@code JsonString} was created by parsing a JSON document, it + /// preserves the text representation of the corresponding JSON String. Otherwise, + /// the {@code value} is escaped to produce the JSON {@code String}. + /// + /// @see #value() String toString(); - /** - * {@return the {@code String} value represented by this {@code JsonString}} - * If this {@code JsonString} was created by parsing a JSON document, any - * escaped characters in the original JSON document are converted to their - * unescaped form. - * - * @see #toString() - */ + /// {@return the {@code String} value represented by this {@code JsonString}} + /// If this {@code JsonString} was created by parsing a JSON document, any + /// escaped characters in the original JSON document are converted to their + /// unescaped form. + /// + /// @see #toString() String value(); - /** - * {@return true if the given {@code obj} is equal to this {@code JsonString}} - * Two {@code JsonString}s {@code js1} and {@code js2} represent the same value - * if {@code js1.value().equals(js2.value())}. - * - * @see #value() - */ + /// {@return true if the given {@code obj} is equal to this {@code JsonString}} + /// Two {@code JsonString}s {@code js1} and {@code js2} represent the same value + /// if {@code js1.value().equals(js2.value())}. + /// + /// @see #value() @Override boolean equals(Object obj); - /** - * {@return the hash code value of this {@code JsonString}} The hash code of a - * {@code JsonString} is derived from the hash code of {@code JsonString}'s - * {@link #value()}. - * - * @see #value() - */ + /// {@return the hash code value of this {@code JsonString}} The hash code of a + /// {@code JsonString} is derived from the hash code of {@code JsonString}'s + /// {@link #value()}. + /// + /// @see #value() @Override int hashCode(); }