Skip to content

Commit

Permalink
Apply auto-formatting, re #13
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Feb 27, 2024
1 parent 1f82716 commit 2993c99
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 88 deletions.
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,10 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.libj</groupId>
<artifactId>lang</artifactId>
<version>0.8.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.libj</groupId>
<artifactId>io</artifactId>
<version>0.7.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.libj</groupId>
<artifactId>math</artifactId>
<version>0.6.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
67 changes: 35 additions & 32 deletions src/main/java/org/openjax/json/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static class TypeMap {
* @param factory The "JSON to object" factory function of type <code>Type{@link Type &lt;T&gt;}</code>.
* @return {@code this} instance.
*/
public <T>TypeMap put(final Type<T> key, final T factory) {
public <T> TypeMap put(final Type<T> key, final T factory) {
map[key.ordinal()] = factory;
return this;
}
Expand All @@ -114,7 +114,7 @@ public <T>TypeMap put(final Type<T> key, final T factory) {
* @param key The {@link Type key}.
* @return The function of type <code>Type{@link Type &lt;T&gt;}</code> for the provided {@link Type key}.
*/
public <T>T get(final Type<T> key) {
public <T> T get(final Type<T> key) {
return (T)map[key.ordinal()];
}
}
Expand Down Expand Up @@ -449,8 +449,8 @@ private static StringBuilder encode(final StringBuilder builder, final Object ob
* </ul>
*
* @implNote The property values of the specified map may only be instances of {@link Map Map&lt;String,?&gt;}, {@link List
* List&lt;?&gt;}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will
* result in an {@link IllegalArgumentException}.
* List&lt;?&gt;}, {@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&lt;String,?&gt;}, {@link List List&lt;?&gt;}, {@link String},
* {@link Number}, {@link Boolean}, and {@code null}.
* @return A string encoding of the {@code json} object.
Expand All @@ -474,18 +474,18 @@ public static String toString(final Object json) {
* </ul>
*
* @implNote The property values of the specified map may only be instances of {@link Map Map&lt;String,?&gt;}, {@link List
* List&lt;?&gt;}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will
* result in an {@link IllegalArgumentException}.
* List&lt;?&gt;}, {@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&lt;String,?&gt;}, {@link List List&lt;?&gt;}, {@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&lt;String,?&gt;} or member of the {@link List List&lt;?&gt;} is of a class that is not one of {@link Map
* Map&lt;String,?&gt;}, {@link List List&lt;?&gt;}, {@link String}, {@link Number}, {@link Boolean} and {@code null},
* or if {@code indent} is negative.
* Map&lt;String,?&gt;}, {@link List List&lt;?&gt;}, {@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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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&lt;String,?&gt;}, {@link List
* List&lt;?&gt;}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will
* result in an {@link IllegalArgumentException}.
* List&lt;?&gt;}, {@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&lt;String,?&gt;}.
* @return A JSON string encoding of the specified {@link Map Map&lt;String,?&gt;} representing a JSON object.
* @throws IllegalArgumentException If {@code object} is null, or if a property value of the specified {@link Map
Expand All @@ -565,12 +565,12 @@ public static String toString(final Map<String,?> object) {
* {@code object} is null.
*
* @implNote The property values of the specified map may only be instances of {@link Map Map&lt;String,?&gt;}, {@link List
* List&lt;?&gt;}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will
* result in an {@link IllegalArgumentException}.
* List&lt;?&gt;}, {@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&lt;String,?&gt;}.
* @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&lt;String,?&gt;} representing a JSON object.
* @throws IllegalArgumentException If {@code object} is null, or if a property value of the specified {@link Map
* Map&lt;String,?&gt;} is of a class that is not one of {@link Map Map&lt;String,?&gt;}, {@link List List&lt;?&gt;},
Expand Down Expand Up @@ -616,14 +616,14 @@ private static StringBuilder toString(final StringBuilder builder, final Map<Str
* {@code null} if {@code array} is null.
*
* @implNote The property values of the specified map may only be instances of {@link Map Map&lt;String,?&gt;}, {@link List
* List&lt;?&gt;}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will
* result in an {@link IllegalArgumentException}.
* List&lt;?&gt;}, {@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&lt;?&gt;}.
* @return A JSON string encoding of the specified {@link List List&lt;?&gt;} representing a JSON array, or {@code null} if
* {@code array} is null.
* @throws IllegalArgumentException If {@code array} is null, or if a member value of the specified {@link List List&lt;?&gt;} is
* of a class that is not one of {@link Map Map&lt;String,?&gt;}, {@link List List&lt;?&gt;}, {@link String},
* {@link Number}, {@link Boolean}, and {@code null}.
* @throws IllegalArgumentException If {@code array} is null, or if a member value of the specified {@link List List&lt;?&gt;} is of
* a class that is not one of {@link Map Map&lt;String,?&gt;}, {@link List List&lt;?&gt;}, {@link String}, {@link Number},
* {@link Boolean}, and {@code null}.
*/
public static String toString(final List<?> array) {
return toString(array, 0);
Expand All @@ -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&lt;String,?&gt;}, {@link List
* List&lt;?&gt;}, {@link String}, {@link Number}, {@link Boolean}, and {@code null}. Objects of other classes will
* result in an {@link IllegalArgumentException}.
* List&lt;?&gt;}, {@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&lt;?&gt;}.
* @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&lt;?&gt;} representing a JSON array, or {@code null} if
* {@code array} is null.
* @throws IllegalArgumentException If a member value of the specified {@link List List&lt;?&gt;} is of a class that is not one of
Expand All @@ -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());
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/openjax/json/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -117,6 +117,7 @@ else if (!characters(reader.buf(), off, len)) {
* Called when <u>token characters</u> are encountered.
* <p>
* Token characters are:
* @formatter:off
* <ul><li>A property key:
* <ul><li>A string that matches:
* <pre>
Expand All @@ -138,6 +139,7 @@ else if (!characters(reader.buf(), off, len)) {
* {@code ^null|true|false$}
* </pre>
* </li></ul></li></ul>
* @formatter:on
*
* @param chars A reference to the underlying {@code char[]} buffer.
* @param start The start index of the token.
Expand Down
34 changes: 16 additions & 18 deletions src/main/java/org/openjax/json/JsonReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -302,8 +300,8 @@ public int getPosition() {
}

/**
* Read the next <u>JSON token</u>, and return a {@linkplain org.libj.lang.Numbers.Composite#encode(int,int) composite}
* {@code long} of the <u>offset index</u> and <u>token length</u>, which can be decoded with
* Read the next <u>JSON token</u>, and return a {@linkplain org.libj.lang.Numbers.Composite#encode(int,int) composite} {@code long}
* of the <u>offset index</u> and <u>token length</u>, which can be decoded with
* {@link org.libj.lang.Numbers.Composite#decodeInt(long,int) Composite#decodeInt(long,int)}.
* <p>
* A <u>JSON token</u> is one of:
Expand Down Expand Up @@ -359,8 +357,8 @@ public int getPosition() {
* </ul>
*
* @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)
Expand Down Expand Up @@ -431,8 +429,8 @@ public void reset() {
* have not yet been returned by {@link #read()}</i>. 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()
Expand All @@ -447,9 +445,9 @@ public int read() throws IOException {
* {@inheritDoc}
* <p>
* 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 <i>the remaining characters of
* the token that have not yet been returned by {@link #read()}</i>. 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 <i>the remaining characters of the
* token that have not yet been returned by {@link #read()}</i>. 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.
Expand Down Expand Up @@ -485,9 +483,9 @@ public int read(final char[] cbuf, int off, int len) throws IOException {
* {@inheritDoc}
* <p>
* 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.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/openjax/json/JsonReplayReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://www.ietf.org/rfc/rfc4627.txt">RFC 4627, Section 2.5</a>.
* 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 <a href="https://www.ietf.org/rfc/rfc4627.txt">RFC 4627, Section 2.5</a>.
* <p>
* {@inheritDoc}
*
Expand Down
Loading

0 comments on commit 2993c99

Please sign in to comment.