From 14ffe1f73e7e8c609a955dd88e23585d92cad423 Mon Sep 17 00:00:00 2001 From: scottf Date: Mon, 4 Aug 2025 15:53:46 -0400 Subject: [PATCH] Use String.replace instead of String.replaceAll --- src/main/java/io/synadia/json/JsonParser.java | 106 +++++++++--------- src/main/java/io/synadia/json/JsonValue.java | 8 +- .../java/io/synadia/json/JsonWriteUtils.java | 28 ++--- 3 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/main/java/io/synadia/json/JsonParser.java b/src/main/java/io/synadia/json/JsonParser.java index a0985fb..d2d7cad 100644 --- a/src/main/java/io/synadia/json/JsonParser.java +++ b/src/main/java/io/synadia/json/JsonParser.java @@ -25,7 +25,7 @@ import java.util.Map; /** - * Class that can parse json to a JsonValue + * Class that can parse JSON to a JsonValue */ public class JsonParser { @@ -40,8 +40,8 @@ public enum Option { } /** - * Parse Json from a char array - * @param json the json + * Parse JSON from a char array + * @param json the JSON * @return the JsonValue * @throws JsonParseException if there is a problem parsing */ @@ -51,8 +51,8 @@ public static JsonValue parse(char @Nullable [] json) throws JsonParseException } /** - * Parse Json from a char array, starting at the index - * @param json the json + * Parse JSON from a char array, starting at the index + * @param json the JSON * @param startIndex the starting index in the array * @return the JsonValue * @throws JsonParseException if there is a problem parsing @@ -63,8 +63,8 @@ public static JsonValue parse(char @Nullable [] json, int startIndex) throws Jso } /** - * Parse Json from a char array - * @param json the json + * Parse JSON from a char array + * @param json the JSON * @param options options for how to parse * @return the JsonValue * @throws JsonParseException if there is a problem parsing @@ -75,8 +75,8 @@ public static JsonValue parse(char @Nullable [] json, @Nullable Option... option } /** - * Parse Json from a char array - * @param json the json + * Parse JSON from a char array + * @param json the JSON * @param startIndex the starting index in the array * @param options options for how to parse * @return the JsonValue @@ -89,8 +89,8 @@ public static JsonValue parse(char @Nullable [] json, int startIndex, @Nullable /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @return the JsonValue * @throws JsonParseException if there is a problem parsing */ @@ -101,8 +101,8 @@ public static JsonValue parse(String json) throws JsonParseException { /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @param startIndex the starting index in the string * @return the JsonValue * @throws JsonParseException if there is a problem parsing @@ -113,8 +113,8 @@ public static JsonValue parse(String json, int startIndex) throws JsonParseExcep } /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @param options options for how to parse * @return the JsonValue * @throws JsonParseException if there is a problem parsing @@ -125,8 +125,8 @@ public static JsonValue parse(String json, @Nullable Option... options) throws J } /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @param startIndex the starting index in the array * @param options options for how to parse * @return the JsonValue @@ -138,8 +138,8 @@ public static JsonValue parse(String json, int startIndex, @Nullable Option... o } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @return the JsonValue * @throws JsonParseException if there is a problem parsing */ @@ -149,8 +149,8 @@ public static JsonValue parse(byte[] json) throws JsonParseException { } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @param startIndex the starting index in the array * @return the JsonValue * @throws JsonParseException if there is a problem parsing @@ -161,8 +161,8 @@ public static JsonValue parse(byte[] json, int startIndex) throws JsonParseExcep } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @param options options for how to parse * @return the JsonValue * @throws JsonParseException if there is a problem parsing @@ -173,8 +173,8 @@ public static JsonValue parse(byte[] json, @Nullable Option... options) throws J } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @param startIndex the starting index in the array * @param options options for how to parse * @return the JsonValue @@ -186,8 +186,8 @@ public static JsonValue parse(byte[] json, int startIndex, @Nullable Option... o } /** - * Parse Json from a char array - * @param json the json + * Parse JSON from a char array + * @param json the JSON * @return the JsonValue * @throws RuntimeException if there is a problem parsing */ @@ -198,8 +198,8 @@ public static JsonValue parseUnchecked(char @Nullable [] json) { } /** - * Parse Json from a char array - * @param json the json + * Parse JSON from a char array + * @param json the JSON * @param startIndex the starting index in the array * @return the JsonValue * @throws RuntimeException if there is a problem parsing @@ -211,8 +211,8 @@ public static JsonValue parseUnchecked(char @Nullable [] json, int startIndex) { } /** - * Parse Json from a char array - * @param json the json + * Parse JSON from a char array + * @param json the JSON * @param options options for how to parse * @return the JsonValue * @throws RuntimeException if there is a problem parsing @@ -224,8 +224,8 @@ public static JsonValue parseUnchecked(char @Nullable [] json, @Nullable Option. } /** - * Parse Json from a char array - * @param json the json + * Parse JSON from a char array + * @param json the JSON * @param startIndex the starting index in the array * @param options options for how to parse * @return the JsonValue @@ -238,8 +238,8 @@ public static JsonValue parseUnchecked(char @Nullable [] json, int startIndex, @ } /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @return the JsonValue * @throws RuntimeException if there is a problem parsing */ @@ -250,8 +250,8 @@ public static JsonValue parseUnchecked(String json) { } /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @param startIndex the starting index in the string * @return the JsonValue * @throws RuntimeException if there is a problem parsing @@ -263,8 +263,8 @@ public static JsonValue parseUnchecked(String json, int startIndex) { } /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @param options options for how to parse * @return the JsonValue * @throws RuntimeException if there is a problem parsing @@ -276,8 +276,8 @@ public static JsonValue parseUnchecked(String json, @Nullable Option... options) } /** - * Parse Json from a String - * @param json the json + * Parse JSON from a String + * @param json the JSON * @param startIndex the starting index in the string * @param options options for how to parse * @return the JsonValue @@ -290,8 +290,8 @@ public static JsonValue parseUnchecked(String json, int startIndex, @Nullable Op } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @return the JsonValue * @throws RuntimeException if there is a problem parsing */ @@ -302,8 +302,8 @@ public static JsonValue parseUnchecked(byte[] json) { } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @param startIndex the starting index in the array * @return the JsonValue * @throws RuntimeException if there is a problem parsing @@ -315,8 +315,8 @@ public static JsonValue parseUnchecked(byte[] json, int startIndex) { } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @param options options for how to parse * @return the JsonValue * @throws RuntimeException if there is a problem parsing @@ -328,8 +328,8 @@ public static JsonValue parseUnchecked(byte[] json, @Nullable Option... options) } /** - * Parse Json from a byte array - * @param json the json + * Parse JSON from a byte array + * @param json the JSON * @param startIndex the starting index in the array * @param options options for how to parse * @return the JsonValue @@ -352,7 +352,7 @@ public static JsonValue parseUnchecked(byte[] json, int startIndex, @Nullable Op /** * Create a new JsonParse object from a char array - * @param json the json + * @param json the JSON */ public JsonParser(char @Nullable [] json) { this(json, 0); @@ -360,7 +360,7 @@ public JsonParser(char @Nullable [] json) { /** * Create a new JsonParse object from a char array - * @param json the json + * @param json the JSON * @param options options for how to parse */ public JsonParser(char @Nullable [] json, @Nullable Option... options) { @@ -369,7 +369,7 @@ public JsonParser(char @Nullable [] json, @Nullable Option... options) { /** * Create a new JsonParse object from a char array - * @param json the json + * @param json the JSON * @param startIndex the starting index in the array * @param options options for how to parse */ @@ -390,7 +390,7 @@ public JsonParser(char @Nullable [] json, int startIndex, @Nullable Option... op } /** - * Parse the json + * Parse the JSON * @return a JsonValue * @throws JsonParseException if there is a problem parsing */ diff --git a/src/main/java/io/synadia/json/JsonValue.java b/src/main/java/io/synadia/json/JsonValue.java index b3183ce..7b6dd4d 100644 --- a/src/main/java/io/synadia/json/JsonValue.java +++ b/src/main/java/io/synadia/json/JsonValue.java @@ -409,18 +409,18 @@ else if (type == JsonValueType.ARRAY) { } /** - * Create a json string using the class simple name as the key for the entire object + * Create a JSON string using the class simple name as the key for the entire object * @param c the class - * @return the json string + * @return the JSON string */ public String toString(Class c) { return JsonWriteUtils.toKey(c) + toJson(); } /** - * Create a json string using the class simple name as the key for the entire object + * Create a JSON string using the class simple name as the key for the entire object * @param key the field name - * @return the json string + * @return the JSON string */ public String toString(String key) { return JsonWriteUtils.toKey(key) + toJson(); diff --git a/src/main/java/io/synadia/json/JsonWriteUtils.java b/src/main/java/io/synadia/json/JsonWriteUtils.java index ae0f8e0..2703396 100644 --- a/src/main/java/io/synadia/json/JsonWriteUtils.java +++ b/src/main/java/io/synadia/json/JsonWriteUtils.java @@ -105,7 +105,7 @@ public static StringBuilder endArray(@NotNull StringBuilder sb) { } /** - * Create StringBuilder with an open squiggly bracket { and a system specific line separator + * Create StringBuilder with an open squiggly bracket { and a system-specific line separator * @return the StringBuilder */ @NotNull @@ -114,7 +114,7 @@ public static StringBuilder beginFormattedJson() { } /** - * End a StringBuilder of formatted json with the system specific line separator + * End a StringBuilder of formatted JSON with the system-specific line separator * @param sb the StringBuilder to append to * @return the string */ @@ -124,11 +124,11 @@ public static String endFormattedJson(@NotNull StringBuilder sb) { return sb.append(System.lineSeparator()) .append("}") .toString() - .replaceAll(",", "," + System.lineSeparator() + " "); + .replace(",", "," + System.lineSeparator() + " "); } /** - * Appends a field for a raw json value unless the json string is null or empty. + * Appends a field for a raw JSON value unless the JSON string is null or empty. * @param sb string builder * @param fieldName the field name * @param json raw JSON @@ -389,7 +389,7 @@ public interface ListValueResolver { default boolean appendable(T t) { return t != null; } /** - * Append the object's json value representation + * Append the object's JSON value representation * @param sb the target SringBuilder * @param t the object */ @@ -581,7 +581,7 @@ public static > void addEnumWhenNot(@NotNull StringBuilder sb, // ---------------------------------------------------------------------------------------------------- /** - * Get the key string portion of a json key value using the class simple name as the field name + * Get the key string portion of a JSON key value using the class simple name as the field name * @param c the class * @return the key string */ @@ -591,7 +591,7 @@ public static String toKey(@NotNull Class c) { } /** - * Get the key string portion of a json key value using the class simple name as the field name + * Get the key string portion of a JSON key value using the class simple name as the field name * @param fieldName the field name * @return the key string */ @@ -607,7 +607,7 @@ private static String indent(int level) { } /** - * Get a string formatted for easy reading. Assumes the object's toString returns valid json. + * Get a string formatted for easy reading. Assumes the object's toString returns valid JSON. * @param o the object * @return the formatted string */ @@ -627,8 +627,8 @@ public static String getFormatted(@NotNull JsonSerializable js) { } /** - * Get a string formatted for easy reading. Assumes valid json - * @param json the json string + * Get a string formatted for easy reading. Assumes valid JSON + * @param json the JSON string * @return the formatted string */ @NotNull @@ -689,7 +689,7 @@ public static String getFormatted(@NotNull String json) { } /** - * Print the object to System.out, formatted for easy reading. Assumes the object's toString returns valid json. + * Print the object to System.out, formatted for easy reading. Assumes the object's toString returns valid JSON. * @param o the object */ public static void printFormatted(@NotNull Object o) { @@ -697,7 +697,7 @@ public static void printFormatted(@NotNull Object o) { } /** - * Print the json to System.out, formatted for easy reading + * Print the JSON to System.out, formatted for easy reading * @param js a JsonSerializable object */ public static void printFormatted(@NotNull JsonSerializable js) { @@ -705,8 +705,8 @@ public static void printFormatted(@NotNull JsonSerializable js) { } /** - * Print the string to System.out, formatted for easy reading. Assumes valid json - * @param json the json string + * Print the string to System.out, formatted for easy reading. Assumes valid JSON + * @param json the JSON string */ public static void printFormatted(@NotNull String json) { System.out.println(getFormatted(json));