From 2993c997810e90205b82a9595db9723f8fb0728e Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Tue, 27 Feb 2024 11:51:46 +0700 Subject: [PATCH] Apply auto-formatting, re #13 --- pom.xml | 10 --- src/main/java/org/openjax/json/JSON.java | 67 ++++++++++--------- .../java/org/openjax/json/JsonParser.java | 6 +- .../java/org/openjax/json/JsonReader.java | 34 +++++----- .../org/openjax/json/JsonReplayReader.java | 4 +- src/main/java/org/openjax/json/JsonUtil.java | 63 +++++++++++------ .../org/openjax/json/JsonReaderRTest.java | 2 +- src/test/java/org/openjax/json/JsonTest.java | 2 +- 8 files changed, 100 insertions(+), 88 deletions(-) diff --git a/pom.xml b/pom.xml index 2c42a1e..dab22ee 100644 --- a/pom.xml +++ b/pom.xml @@ -70,20 +70,10 @@ test - - org.libj - lang - 0.8.1-SNAPSHOT - org.libj io 0.7.9-SNAPSHOT - - org.libj - math - 0.6.8-SNAPSHOT - \ No newline at end of file diff --git a/src/main/java/org/openjax/json/JSON.java b/src/main/java/org/openjax/json/JSON.java index 72a04d5..1a75ea3 100644 --- a/src/main/java/org/openjax/json/JSON.java +++ b/src/main/java/org/openjax/json/JSON.java @@ -102,7 +102,7 @@ public static class TypeMap { * @param factory The "JSON to object" factory function of type Type{@link Type <T>}. * @return {@code this} instance. */ - public TypeMap put(final Type key, final T factory) { + public TypeMap put(final Type key, final T factory) { map[key.ordinal()] = factory; return this; } @@ -114,7 +114,7 @@ public TypeMap put(final Type key, final T factory) { * @param key The {@link Type key}. * @return The function of type Type{@link Type <T>} for the provided {@link Type key}. */ - public T get(final Type key) { + public T get(final Type key) { return (T)map[key.ordinal()]; } } @@ -449,8 +449,8 @@ private static StringBuilder encode(final StringBuilder builder, final Object ob * * * @implNote The property values of the specified map may only be instances of {@link Map Map<String,?>}, {@link List - * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will - * result in an {@link IllegalArgumentException}. + * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will result + * in an {@link IllegalArgumentException}. * @param json The JSON value represented as a {@link Map Map<String,?>}, {@link List List<?>}, {@link String}, * {@link Number}, {@link Boolean}, and {@code null}. * @return A string encoding of the {@code json} object. @@ -474,18 +474,18 @@ public static String toString(final Object json) { * * * @implNote The property values of the specified map may only be instances of {@link Map Map<String,?>}, {@link List - * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will - * result in an {@link IllegalArgumentException}. + * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will result + * in an {@link IllegalArgumentException}. * @param json The JSON value represented as a {@link Map Map<String,?>}, {@link List List<?>}, {@link String}, * {@link Number}, {@link Boolean}, and {@code null}. - * @param indent Number of spaces to indent child elements. If the specified indent value is greater than {@code 0}, child - * elements are indented and placed on a new line. If the indent value is {@code 0}, child elements are not indented, nor - * placed on a new line. + * @param indent Number of spaces to indent child elements. If the specified indent value is greater than {@code 0}, child elements + * are indented and placed on a new line. If the indent value is {@code 0}, child elements are not indented, nor placed on + * a new line. * @return A string encoding of the {@code json} object. * @throws IllegalArgumentException If {@code json} is null, or if {@code json} or a property value of the specified {@link Map * Map<String,?>} or member of the {@link List List<?>} is of a class that is not one of {@link Map - * Map<String,?>}, {@link List List<?>}, {@link String}, {@link Number}, {@link Boolean} and {@code null}, - * or if {@code indent} is negative. + * Map<String,?>}, {@link List List<?>}, {@link String}, {@link Number}, {@link Boolean} and {@code null}, or + * if {@code indent} is negative. */ @SuppressWarnings("unchecked") public static String toString(final Object json, final int indent) { @@ -532,8 +532,8 @@ public static String toString(final float json) { } /** - * Returns a JSON string encoding of the provided {@code double}. If the provided {@code double} represents {@code NaN} or - * infinity, this method returns {@code "null"}. Otherwise, for all other {@code double} values, this method returns + * Returns a JSON string encoding of the provided {@code double}. If the provided {@code double} represents {@code NaN} or infinity, + * this method returns {@code "null"}. Otherwise, for all other {@code double} values, this method returns * {@link Double#toString(double)}. * * @param json The {@code double} to encode. @@ -548,8 +548,8 @@ public static String toString(final double json) { * {@code object} is null. * * @implNote The property values of the specified map may only be instances of {@link Map Map<String,?>}, {@link List - * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will - * result in an {@link IllegalArgumentException}. + * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will result + * in an {@link IllegalArgumentException}. * @param object The JSON object, represented as a {@link Map Map<String,?>}. * @return A JSON string encoding of the specified {@link Map Map<String,?>} representing a JSON object. * @throws IllegalArgumentException If {@code object} is null, or if a property value of the specified {@link Map @@ -565,12 +565,12 @@ public static String toString(final Map object) { * {@code object} is null. * * @implNote The property values of the specified map may only be instances of {@link Map Map<String,?>}, {@link List - * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will - * result in an {@link IllegalArgumentException}. + * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will result + * in an {@link IllegalArgumentException}. * @param object The JSON object, represented as a {@link Map Map<String,?>}. - * @param indent Number of spaces to indent child elements. If the specified indent value is greater than {@code 0}, child - * elements are indented and placed on a new line. If the indent value is {@code 0}, child elements are not indented, nor - * placed on a new line. + * @param indent Number of spaces to indent child elements. If the specified indent value is greater than {@code 0}, child elements + * are indented and placed on a new line. If the indent value is {@code 0}, child elements are not indented, nor placed on + * a new line. * @return A JSON string encoding of the specified {@link Map Map<String,?>} representing a JSON object. * @throws IllegalArgumentException If {@code object} is null, or if a property value of the specified {@link Map * Map<String,?>} is of a class that is not one of {@link Map Map<String,?>}, {@link List List<?>}, @@ -616,14 +616,14 @@ private static StringBuilder toString(final StringBuilder builder, final Map array) { return toString(array, 0); @@ -634,12 +634,12 @@ public static String toString(final List array) { * array, or {@code null} if {@code array} is null. * * @implNote The property values of the specified map may only be instances of {@link Map Map<String,?>}, {@link List - * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will - * result in an {@link IllegalArgumentException}. + * List<?>}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will result + * in an {@link IllegalArgumentException}. * @param array The JSON array, represented as a {@link List List<?>}. - * @param indent Number of spaces to indent child elements. If the specified indent value is greater than {@code 0}, child - * elements are indented and placed on a new line. If the indent value is {@code 0}, child elements are not indented, nor - * placed on a new line. + * @param indent Number of spaces to indent child elements. If the specified indent value is greater than {@code 0}, child elements + * are indented and placed on a new line. If the indent value is {@code 0}, child elements are not indented, nor placed on + * a new line. * @return A JSON string encoding of the specified {@link List List<?>} representing a JSON array, or {@code null} if * {@code array} is null. * @throws IllegalArgumentException If a member value of the specified {@link List List<?>} is of a class that is not one of @@ -657,12 +657,15 @@ private static StringBuilder toString(final StringBuilder builder, final List final int i$ = array.size(); if (i$ > 0) { if (CollectionUtil.isRandomAccess(array)) { - int i = 0; do // [RA] + int i = 0; + do // [RA] backUp = toString(builder, array.get(i), indent, spaces == -1 ? -1 : spaces + indent, backUp, i); while (++i < i$); } else { - int i = -1; final Iterator it = array.iterator(); do // [I] + int i = -1; + final Iterator it = array.iterator(); + do // [I] backUp = toString(builder, it.next(), indent, spaces == -1 ? -1 : spaces + indent, backUp, ++i); while (it.hasNext()); } diff --git a/src/main/java/org/openjax/json/JsonParser.java b/src/main/java/org/openjax/json/JsonParser.java index ee4915d..c248da0 100644 --- a/src/main/java/org/openjax/json/JsonParser.java +++ b/src/main/java/org/openjax/json/JsonParser.java @@ -27,8 +27,8 @@ public interface JsonParser { * * @param reader The {@link JsonReader} from which JSON is read. * @return {@code true} if the document has been read entirely. {@code false} if parsing was aborted by a handler callback. If a - * handler aborts parsing, subsequent calls to {@link #parse(JsonReader)} will resume from the position at which parsing - * was previously aborted. + * handler aborts parsing, subsequent calls to {@link #parse(JsonReader)} will resume from the position at which parsing was + * previously aborted. * @throws IOException If an I/O error has occurred. * @throws JsonParseException If the content is not a well formed JSON term. * @throws NullPointerException If {@code reader} is null. @@ -117,6 +117,7 @@ else if (!characters(reader.buf(), off, len)) { * Called when token characters are encountered. *

* Token characters are: + * @formatter:off *

  • A property key: *
    • A string that matches: *
      @@ -138,6 +139,7 @@ else if (!characters(reader.buf(), off, len)) {
          * {@code ^null|true|false$}
          * 
      *
+ * @formatter:on * * @param chars A reference to the underlying {@code char[]} buffer. * @param start The start index of the token. diff --git a/src/main/java/org/openjax/json/JsonReader.java b/src/main/java/org/openjax/json/JsonReader.java index 85330af..c9a87c2 100644 --- a/src/main/java/org/openjax/json/JsonReader.java +++ b/src/main/java/org/openjax/json/JsonReader.java @@ -252,11 +252,9 @@ private int setIndex0(int index) { } /** - * Returns the number of tokens read thus far. The value returned by this method defines the upper bound of - * {@link #setIndex(int)}. + * Returns the number of tokens read thus far. The value returned by this method defines the upper bound of {@link #setIndex(int)}. * - * @return The number of tokens read thus far. The value returned by this method defines the upper bound of - * {@link #setIndex(int)}. + * @return The number of tokens read thus far. The value returned by this method defines the upper bound of {@link #setIndex(int)}. */ public int size() { return positions.size(); @@ -302,8 +300,8 @@ public int getPosition() { } /** - * Read the next JSON token, and return a {@linkplain org.libj.lang.Numbers.Composite#encode(int,int) composite} - * {@code long} of the offset index and token length, which can be decoded with + * Read the next JSON token, and return a {@linkplain org.libj.lang.Numbers.Composite#encode(int,int) composite} {@code long} + * of the offset index and token length, which can be decoded with * {@link org.libj.lang.Numbers.Composite#decodeInt(long,int) Composite#decodeInt(long,int)}. *

* A JSON token is one of: @@ -359,8 +357,8 @@ public int getPosition() { * * * @implNote If this instance ignores whitespace, this method will skip whitespace tokens. - * @return A {@linkplain org.libj.lang.Numbers.Composite#encode(int,int) composite} {@code long} of the offset index and length - * into the underlying {@link JsonReader}, or {@code -1} if the end of content has been reached. + * @return A {@linkplain org.libj.lang.Numbers.Composite#encode(int,int) composite} {@code long} of the offset index and length into + * the underlying {@link JsonReader}, or {@code -1} if the end of content has been reached. * @throws IOException If an I/O error has occurred. * @throws JsonParseException If the content is not well formed. * @see org.libj.lang.Numbers.Composite#decodeInt(long,int) @@ -431,8 +429,8 @@ public void reset() { * have not yet been returned by {@link #read()}. Characters read with this method undergo the same token-level error checking * as in {@link #readTokenStart()} or {@link #readToken()}. * - * @return The character read, as an integer in the range 0 to 65535 ({@code 0x00-0xffff}), or -1 if the end of the stream has - * been reached. + * @return The character read, as an integer in the range 0 to 65535 ({@code 0x00-0xffff}), or -1 if the end of the stream has been + * reached. * @throws IOException If an I/O error has occurred. * @throws JsonParseException If the content is not well formed. * @see #readTokenStart() @@ -447,9 +445,9 @@ public int read() throws IOException { * {@inheritDoc} *

* Characters read with this method advance the characters of the tokens to which they belong. Therefore, when partially reading a - * token with {@link #read(char[],int,int)}, subsequent calls to {@link #readToken()} will return the remaining characters of - * the token that have not yet been returned by {@link #read()}. Characters read with this method undergo the same token-level - * error checking as in {@link #readTokenStart()} or {@link #readToken()}. + * token with {@link #read(char[],int,int)}, subsequent calls to {@link #readToken()} will return the remaining characters of the + * token that have not yet been returned by {@link #read()}. Characters read with this method undergo the same token-level error + * checking as in {@link #readTokenStart()} or {@link #readToken()}. * * @param cbuf Destination buffer. * @param off Offset at which to start storing characters. @@ -485,9 +483,9 @@ public int read(final char[] cbuf, int off, int len) throws IOException { * {@inheritDoc} *

* Characters read with this method advance the characters of the tokens to which they belong. Therefore, when partially reading a - * token with {@link #read(char[])}, subsequent calls to {@link #readToken()} will return the remaining characters of the token - * that have not yet been returned by {@link #read()}. Characters read with this method undergo the same token-level validation as - * in {@link #readTokenStart()} or {@link #readToken()}. + * token with {@link #read(char[])}, subsequent calls to {@link #readToken()} will return the remaining characters of the token that + * have not yet been returned by {@link #read()}. Characters read with this method undergo the same token-level validation as in + * {@link #readTokenStart()} or {@link #readToken()}. * * @param cbuf Destination buffer. * @return The number of characters read, or -1 if the end of the stream has been reached. @@ -628,8 +626,8 @@ else if (getStartPosition(index + 1) == -1) { } /** - * Read until the end of the next token, and return the start index of the token that was just read. The end index of the token - * can be retrieved with a subsequent call to {@link #getPosition()}. If the end of content has been reached, this method returns + * Read until the end of the next token, and return the start index of the token that was just read. The end index of the token can + * be retrieved with a subsequent call to {@link #getPosition()}. If the end of content has been reached, this method returns * {@code -1}. * * @return The start index of the next token. diff --git a/src/main/java/org/openjax/json/JsonReplayReader.java b/src/main/java/org/openjax/json/JsonReplayReader.java index 4e27ef3..725d32f 100644 --- a/src/main/java/org/openjax/json/JsonReplayReader.java +++ b/src/main/java/org/openjax/json/JsonReplayReader.java @@ -64,8 +64,8 @@ class JsonReplayReader extends ReplayReader { } /** - * Reads a single character, and transparently unescapes string-literal unicode ({@code "\u000A"}) and two-character - * ({@code "\n"}) escape codes into UTF-8 as defined in RFC 4627, Section 2.5. + * Reads a single character, and transparently unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) + * escape codes into UTF-8 as defined in RFC 4627, Section 2.5. *

* {@inheritDoc} * diff --git a/src/main/java/org/openjax/json/JsonUtil.java b/src/main/java/org/openjax/json/JsonUtil.java index fd6719f..23e9d44 100644 --- a/src/main/java/org/openjax/json/JsonUtil.java +++ b/src/main/java/org/openjax/json/JsonUtil.java @@ -42,11 +42,18 @@ public static boolean isStructural(final int ch) { } /** - * Tests whether the specified {@code int} is JSON whitespace char, which is - * one of: + * Tests whether the specified {@code int} is JSON whitespace char, which is one of: * *

-   * {@code ' '}, {@code '\n'}, {@code '\r'}, or {@code '\t'}
+   * {@code
+   * ' '
+   * }, {@code
+   * '\n'
+   * }, {@code
+   * '\r'
+   * }, or {@code
+   * '\t'
+   * }
    * 
* * @param ch The {@code int} to test. @@ -73,7 +80,7 @@ public static boolean isWhitespace(final int ch) { * @throws NullPointerException If {@code str} is null. */ @SuppressWarnings("unchecked") - public static T parseNumber(final Class type, CharSequence str, final boolean strict) throws JsonParseException { + public static T parseNumber(final Class type, CharSequence str, final boolean strict) throws JsonParseException { if (str.length() == 0) throw new IllegalArgumentException("Empty string"); @@ -182,9 +189,9 @@ else if (last == '0' && i == expStart + (first == '~' ? 2 : 1)) { } /** - * Escapes characters in the specified string that must be escaped as defined in - * RFC 4627, Section 2.5. This includes quotation mark ({@code "\""}), reverse - * solidus ({@code "\\"}), and the control characters ({@code U+0000} through {@code U+001F}). + * Escapes characters in the specified string that must be escaped as defined in RFC + * 4627, Section 2.5. This includes quotation mark ({@code "\""}), reverse solidus ({@code "\\"}), and the control characters + * ({@code U+0000} through {@code U+001F}). *

* This method escapes the following characters in string-literal two-character form: * @@ -202,9 +209,9 @@ public static StringBuilder escape(final CharSequence str) { } /** - * Escapes characters in the specified string that must be escaped as defined in - * RFC 4627, Section 2.5. This includes quotation mark ({@code "\""}), reverse - * solidus ({@code "\\"}), and the control characters ({@code U+0000} through {@code U+001F}). + * Escapes characters in the specified string that must be escaped as defined in RFC + * 4627, Section 2.5. This includes quotation mark ({@code "\""}), reverse solidus ({@code "\\"}), and the control characters + * ({@code U+0000} through {@code U+001F}). *

* This method escapes the following characters in string-literal two-character form: * @@ -222,29 +229,35 @@ public static StringBuilder escape(final StringBuilder out, final CharSequence s for (int i = 0, i$ = str.length(); i < i$; ++i) { // [N] final char ch = str.charAt(i); /* - * From RFC 4627, "All Unicode characters may be placed within the quotation marks except for the characters that must be - * escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)." + * From RFC 4627, "All Unicode characters may be placed within the quotation marks except for the characters that must be escaped: + * quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)." */ switch (ch) { case '"': case '\\': out.append('\\').append(ch); break; + case '\n': out.append("\\n"); break; + case '\r': out.append("\\r"); break; + case '\t': out.append("\\t"); break; + case '\b': out.append("\\b"); break; + case '\f': out.append("\\f"); break; + default: if (ch <= 0x1F) out.append(String.format("\\u%04x", (int)ch)); @@ -303,29 +316,35 @@ public static StringBuilder escape(final StringBuilder out, final char[] chars, for (int i = offset, length = offset + len; i < length; ++i) { // [N] final char ch = chars[i]; /* - * From RFC 4627, "All Unicode characters may be placed within the quotation marks except for the characters that must be - * escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)." + * From RFC 4627, "All Unicode characters may be placed within the quotation marks except for the characters that must be escaped: + * quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)." */ switch (ch) { case '"': case '\\': out.append('\\').append(ch); break; + case '\n': out.append("\\n"); break; + case '\r': out.append("\\r"); break; + case '\t': out.append("\\t"); break; + case '\b': out.append("\\b"); break; + case '\f': out.append("\\f"); break; + default: if (ch <= 0x1F) out.append(String.format("\\u%04x", (int)ch)); @@ -338,8 +357,8 @@ public static StringBuilder escape(final StringBuilder out, final char[] chars, } /** - * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double - * quote ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in + * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double quote + * ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in * RFC 4627, Section 2.5. *

* This method deliberately excludes the double quote ({@code "\""}) and reverse solidus ({@code "\\"}), as these characters are @@ -358,8 +377,8 @@ public static StringBuilder unescapeForString(final CharSequence str) { } /** - * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double - * quote ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in + * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double quote + * ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in * RFC 4627, Section 2.5. *

* This method deliberately excludes the double quote ({@code "\""}) and reverse solidus ({@code "\\"}), as these characters are @@ -409,8 +428,8 @@ else if (ch == 'u') { } /** - * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double - * quote ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in + * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double quote + * ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in * RFC 4627, Section 2.5. *

* This method deliberately excludes the double quote ({@code "\""}) and reverse solidus ({@code "\\"}), as these characters are @@ -432,8 +451,8 @@ public static StringBuilder unescapeForString(final char[] chars, final int offs } /** - * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double - * quote ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in + * Unescapes string-literal unicode ({@code "\u000A"}) and two-character ({@code "\n"}) escape codes, except for the double quote + * ({@code "\""}) and reverse solidus ({@code "\\"}), into UTF-8 as defined in * RFC 4627, Section 2.5. *

* This method deliberately excludes the double quote ({@code "\""}) and reverse solidus ({@code "\\"}), as these characters are diff --git a/src/test/java/org/openjax/json/JsonReaderRTest.java b/src/test/java/org/openjax/json/JsonReaderRTest.java index f960aa0..68d1181 100644 --- a/src/test/java/org/openjax/json/JsonReaderRTest.java +++ b/src/test/java/org/openjax/json/JsonReaderRTest.java @@ -34,7 +34,7 @@ public void test() throws RunnerException { final Options options = new OptionsBuilder() .include(".*" + JsonReaderRTest.class.getSimpleName() + ".*") .warmupIterations(1) -// .addProfiler(HotspotMemoryProfiler.class) + // .addProfiler(HotspotMemoryProfiler.class) .measurementIterations(5) .forks(1) .build(); diff --git a/src/test/java/org/openjax/json/JsonTest.java b/src/test/java/org/openjax/json/JsonTest.java index 3a45820..d52617e 100644 --- a/src/test/java/org/openjax/json/JsonTest.java +++ b/src/test/java/org/openjax/json/JsonTest.java @@ -49,7 +49,7 @@ public void test() throws IOException, JsonParseException { for (int i = 0; i < 100; ++i) { // [N] final String json = JSON.toString(object, i); -// System.err.println(json + "\n"); + // System.err.println(json + "\n"); assertEquals(json, JSON.toString(JSON.parse(json), i)); } }