This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit d1fde0d4f4e76798ccf541908134314a8c81d833 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jul 24 11:18:17 2021 -0400 Sort members. --- .../text/translate/CharSequenceTranslator.java | 42 +++++----- .../commons/text/translate/CsvTranslators.java | 32 ++++---- .../text/translate/NumericEntityEscaper.java | 66 +++++++-------- .../text/translate/NumericEntityUnescaper.java | 8 +- .../commons/text/translate/OctalUnescaper.java | 40 ++++----- .../text/translate/SinglePassTranslator.java | 20 ++--- .../commons/text/translate/UnicodeEscaper.java | 96 +++++++++++----------- 7 files changed, 152 insertions(+), 152 deletions(-) diff --git a/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java b/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java index fa80a2b..109c768 100644 --- a/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java +++ b/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java @@ -41,18 +41,15 @@ public abstract class CharSequenceTranslator { 'C', 'D', 'E', 'F'}; /** - * Translate a set of codepoints, represented by an int index into a CharSequence, - * into another set of codepoints. The number of codepoints consumed must be returned, - * and the only IOExceptions thrown must be from interacting with the Writer so that - * the top level API may reliably ignore StringWriter IOExceptions. + * Returns an upper case hexadecimal {@code String} for the given + * character. * - * @param input CharSequence that is being translated - * @param index int representing the current point of translation - * @param writer Writer to translate the text to - * @return int count of codepoints consumed - * @throws IOException if and only if the Writer produces an IOException + * @param codepoint The codepoint to convert. + * @return An upper case hexadecimal {@code String} */ - public abstract int translate(CharSequence input, int index, Writer writer) throws IOException; + public static String hex(final int codepoint) { + return Integer.toHexString(codepoint).toUpperCase(Locale.ENGLISH); + } /** * Helper for non-Writer usage. @@ -74,6 +71,20 @@ public abstract class CharSequenceTranslator { } /** + * Translate a set of codepoints, represented by an int index into a CharSequence, + * into another set of codepoints. The number of codepoints consumed must be returned, + * and the only IOExceptions thrown must be from interacting with the Writer so that + * the top level API may reliably ignore StringWriter IOExceptions. + * + * @param input CharSequence that is being translated + * @param index int representing the current point of translation + * @param writer Writer to translate the text to + * @return int count of codepoints consumed + * @throws IOException if and only if the Writer produces an IOException + */ + public abstract int translate(CharSequence input, int index, Writer writer) throws IOException; + + /** * Translate an input onto a Writer. This is intentionally final as its algorithm is * tightly coupled with the abstract method of this class. * @@ -127,15 +138,4 @@ public abstract class CharSequenceTranslator { return new AggregateTranslator(newArray); } - /** - * Returns an upper case hexadecimal {@code String} for the given - * character. - * - * @param codepoint The codepoint to convert. - * @return An upper case hexadecimal {@code String} - */ - public static String hex(final int codepoint) { - return Integer.toHexString(codepoint).toUpperCase(Locale.ENGLISH); - } - } diff --git a/src/main/java/org/apache/commons/text/translate/CsvTranslators.java b/src/main/java/org/apache/commons/text/translate/CsvTranslators.java index d192b4d..84f786b 100644 --- a/src/main/java/org/apache/commons/text/translate/CsvTranslators.java +++ b/src/main/java/org/apache/commons/text/translate/CsvTranslators.java @@ -33,21 +33,6 @@ import org.apache.commons.lang3.StringUtils; */ public final class CsvTranslators { - /** Comma character. */ - private static final char CSV_DELIMITER = ','; - /** Quote character. */ - private static final char CSV_QUOTE = '"'; - /** Quote character converted to string. */ - private static final String CSV_QUOTE_STR = String.valueOf(CSV_QUOTE); - /** Escaped quote string. */ - private static final String CSV_ESCAPED_QUOTE_STR = CSV_QUOTE_STR + CSV_QUOTE_STR; - /** CSV key characters in an array. */ - private static final char[] CSV_SEARCH_CHARS = - new char[] {CSV_DELIMITER, CSV_QUOTE, CharUtils.CR, CharUtils.LF}; - - /** Hidden constructor. */ - private CsvTranslators() { } - /** * Translator for escaping Comma Separated Values. */ @@ -66,7 +51,6 @@ public final class CsvTranslators { } } } - /** * Translator for unescaping escaped Comma Separated Value entries. */ @@ -91,4 +75,20 @@ public final class CsvTranslators { } } } + /** Comma character. */ + private static final char CSV_DELIMITER = ','; + /** Quote character. */ + private static final char CSV_QUOTE = '"'; + /** Quote character converted to string. */ + private static final String CSV_QUOTE_STR = String.valueOf(CSV_QUOTE); + + /** Escaped quote string. */ + private static final String CSV_ESCAPED_QUOTE_STR = CSV_QUOTE_STR + CSV_QUOTE_STR; + + /** CSV key characters in an array. */ + private static final char[] CSV_SEARCH_CHARS = + new char[] {CSV_DELIMITER, CSV_QUOTE, CharUtils.CR, CharUtils.LF}; + + /** Hidden constructor. */ + private CsvTranslators() { } } diff --git a/src/main/java/org/apache/commons/text/translate/NumericEntityEscaper.java b/src/main/java/org/apache/commons/text/translate/NumericEntityEscaper.java index b19dea2..693cb92 100644 --- a/src/main/java/org/apache/commons/text/translate/NumericEntityEscaper.java +++ b/src/main/java/org/apache/commons/text/translate/NumericEntityEscaper.java @@ -28,32 +28,14 @@ import org.apache.commons.lang3.Range; */ public class NumericEntityEscaper extends CodePointTranslator { - /** whether to escape between the boundaries or outside them. */ - private final boolean between; - - /** range from lowest codepoint to highest codepoint. */ - private final Range<Integer> range; - /** - * Constructs a {@code NumericEntityEscaper} for the specified range. This is - * the underlying method for the other constructors/builders. The {@code below} - * and {@code above} boundaries are inclusive when {@code between} is - * {@code true} and exclusive when it is {@code false}. + * Constructs a {@code NumericEntityEscaper} above the specified value (exclusive). * - * @param below int value representing the lowest codepoint boundary - * @param above int value representing the highest codepoint boundary - * @param between whether to escape between the boundaries or outside them - */ - private NumericEntityEscaper(final int below, final int above, final boolean between) { - this.range = Range.between(below, above); - this.between = between; - } - - /** - * Constructs a {@code NumericEntityEscaper} for all characters. + * @param codepoint above which to escape + * @return The newly created {@code NumericEntityEscaper} instance */ - public NumericEntityEscaper() { - this(0, Integer.MAX_VALUE, true); + public static NumericEntityEscaper above(final int codepoint) { + return outsideOf(0, codepoint); } /** @@ -67,16 +49,6 @@ public class NumericEntityEscaper extends CodePointTranslator { } /** - * Constructs a {@code NumericEntityEscaper} above the specified value (exclusive). - * - * @param codepoint above which to escape - * @return The newly created {@code NumericEntityEscaper} instance - */ - public static NumericEntityEscaper above(final int codepoint) { - return outsideOf(0, codepoint); - } - - /** * Constructs a {@code NumericEntityEscaper} between the specified values (inclusive). * * @param codepointLow above which to escape @@ -98,6 +70,34 @@ public class NumericEntityEscaper extends CodePointTranslator { return new NumericEntityEscaper(codepointLow, codepointHigh, false); } + /** whether to escape between the boundaries or outside them. */ + private final boolean between; + + /** range from lowest codepoint to highest codepoint. */ + private final Range<Integer> range; + + /** + * Constructs a {@code NumericEntityEscaper} for all characters. + */ + public NumericEntityEscaper() { + this(0, Integer.MAX_VALUE, true); + } + + /** + * Constructs a {@code NumericEntityEscaper} for the specified range. This is + * the underlying method for the other constructors/builders. The {@code below} + * and {@code above} boundaries are inclusive when {@code between} is + * {@code true} and exclusive when it is {@code false}. + * + * @param below int value representing the lowest codepoint boundary + * @param above int value representing the highest codepoint boundary + * @param between whether to escape between the boundaries or outside them + */ + private NumericEntityEscaper(final int below, final int above, final boolean between) { + this.range = Range.between(below, above); + this.between = between; + } + /** * {@inheritDoc} */ diff --git a/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java b/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java index 25f4d74..57f1b5e 100644 --- a/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java +++ b/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java @@ -34,10 +34,6 @@ import org.apache.commons.lang3.ArrayUtils; */ public class NumericEntityUnescaper extends CharSequenceTranslator { - /** Default options. */ - private static final EnumSet<OPTION> DEFAULT_OPTIONS = EnumSet - .copyOf(Collections.singletonList(OPTION.semiColonRequired)); - /** Enumerates NumericEntityUnescaper options for unescaping. */ public enum OPTION { @@ -57,6 +53,10 @@ public class NumericEntityUnescaper extends CharSequenceTranslator { errorIfNoSemiColon } + /** Default options. */ + private static final EnumSet<OPTION> DEFAULT_OPTIONS = EnumSet + .copyOf(Collections.singletonList(OPTION.semiColonRequired)); + /** EnumSet of OPTIONS, given from the constructor, read-only. */ private final EnumSet<OPTION> options; diff --git a/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java b/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java index 626ca41..23c33c8 100644 --- a/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java +++ b/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java @@ -32,6 +32,26 @@ import java.io.Writer; public class OctalUnescaper extends CharSequenceTranslator { /** + * Tests if the given char is an octal digit. Octal digits are the character representations of the digits 0 to 7. + * + * @param ch the char to check + * @return true if the given char is the character representation of one of the digits from 0 to 7 + */ + private boolean isOctalDigit(final char ch) { + return ch >= '0' && ch <= '7'; + } + + /** + * Tests if the given char is the character representation of one of the digit from 0 to 3. + * + * @param ch the char to check + * @return true if the given char is the character representation of one of the digits from 0 to 3 + */ + private boolean isZeroToThree(final char ch) { + return ch >= '0' && ch <= '3'; + } + + /** * {@inheritDoc} */ @Override @@ -58,24 +78,4 @@ public class OctalUnescaper extends CharSequenceTranslator { } return 0; } - - /** - * Tests if the given char is an octal digit. Octal digits are the character representations of the digits 0 to 7. - * - * @param ch the char to check - * @return true if the given char is the character representation of one of the digits from 0 to 7 - */ - private boolean isOctalDigit(final char ch) { - return ch >= '0' && ch <= '7'; - } - - /** - * Tests if the given char is the character representation of one of the digit from 0 to 3. - * - * @param ch the char to check - * @return true if the given char is the character representation of one of the digits from 0 to 3 - */ - private boolean isZeroToThree(final char ch) { - return ch >= '0' && ch <= '3'; - } } diff --git a/src/main/java/org/apache/commons/text/translate/SinglePassTranslator.java b/src/main/java/org/apache/commons/text/translate/SinglePassTranslator.java index d9f0012..db82bdb 100644 --- a/src/main/java/org/apache/commons/text/translate/SinglePassTranslator.java +++ b/src/main/java/org/apache/commons/text/translate/SinglePassTranslator.java @@ -25,6 +25,16 @@ import java.io.Writer; */ abstract class SinglePassTranslator extends CharSequenceTranslator { + /** + * A utility method to be used in the {@link #translate(CharSequence, int, Writer)} method. + * + * @return The name of this or the extending class. + */ + private String getClassName() { + final Class<? extends SinglePassTranslator> clazz = this.getClass(); + return clazz.isAnonymousClass() ? clazz.getName() : clazz.getSimpleName(); + } + @Override public int translate(final CharSequence input, final int index, final Writer writer) throws IOException { if (index != 0) { @@ -38,16 +48,6 @@ abstract class SinglePassTranslator extends CharSequenceTranslator { } /** - * A utility method to be used in the {@link #translate(CharSequence, int, Writer)} method. - * - * @return The name of this or the extending class. - */ - private String getClassName() { - final Class<? extends SinglePassTranslator> clazz = this.getClass(); - return clazz.isAnonymousClass() ? clazz.getName() : clazz.getSimpleName(); - } - - /** * Translates whole set of code points passed in input. * * @param input CharSequence that is being translated diff --git a/src/main/java/org/apache/commons/text/translate/UnicodeEscaper.java b/src/main/java/org/apache/commons/text/translate/UnicodeEscaper.java index 488ccc4..2892831 100644 --- a/src/main/java/org/apache/commons/text/translate/UnicodeEscaper.java +++ b/src/main/java/org/apache/commons/text/translate/UnicodeEscaper.java @@ -26,10 +26,52 @@ import java.io.Writer; */ public class UnicodeEscaper extends CodePointTranslator { + /** + * Constructs a {@code UnicodeEscaper} above the specified value (exclusive). + * + * @param codepoint above which to escape + * @return The newly created {@code UnicodeEscaper} instance + */ + public static UnicodeEscaper above(final int codepoint) { + return outsideOf(0, codepoint); + } + /** + * Constructs a {@code UnicodeEscaper} below the specified value (exclusive). + * + * @param codepoint below which to escape + * @return The newly created {@code UnicodeEscaper} instance + */ + public static UnicodeEscaper below(final int codepoint) { + return outsideOf(codepoint, Integer.MAX_VALUE); + } + /** + * Constructs a {@code UnicodeEscaper} between the specified values (inclusive). + * + * @param codepointLow above which to escape + * @param codepointHigh below which to escape + * @return The newly created {@code UnicodeEscaper} instance + */ + public static UnicodeEscaper between(final int codepointLow, final int codepointHigh) { + return new UnicodeEscaper(codepointLow, codepointHigh, true); + } + + /** + * Constructs a {@code UnicodeEscaper} outside of the specified values (exclusive). + * + * @param codepointLow below which to escape + * @param codepointHigh above which to escape + * @return The newly created {@code UnicodeEscaper} instance + */ + public static UnicodeEscaper outsideOf(final int codepointLow, final int codepointHigh) { + return new UnicodeEscaper(codepointLow, codepointHigh, false); + } + /** int value representing the lowest codepoint boundary. */ private final int below; + /** int value representing the highest codepoint boundary. */ private final int above; + /** whether to escape between the boundaries or outside them. */ private final boolean between; @@ -58,45 +100,15 @@ public class UnicodeEscaper extends CodePointTranslator { } /** - * Constructs a {@code UnicodeEscaper} below the specified value (exclusive). - * - * @param codepoint below which to escape - * @return The newly created {@code UnicodeEscaper} instance - */ - public static UnicodeEscaper below(final int codepoint) { - return outsideOf(codepoint, Integer.MAX_VALUE); - } - - /** - * Constructs a {@code UnicodeEscaper} above the specified value (exclusive). - * - * @param codepoint above which to escape - * @return The newly created {@code UnicodeEscaper} instance - */ - public static UnicodeEscaper above(final int codepoint) { - return outsideOf(0, codepoint); - } - - /** - * Constructs a {@code UnicodeEscaper} outside of the specified values (exclusive). + * Converts the given codepoint to a hex string of the form {@code "\\uXXXX"}. * - * @param codepointLow below which to escape - * @param codepointHigh above which to escape - * @return The newly created {@code UnicodeEscaper} instance - */ - public static UnicodeEscaper outsideOf(final int codepointLow, final int codepointHigh) { - return new UnicodeEscaper(codepointLow, codepointHigh, false); - } - - /** - * Constructs a {@code UnicodeEscaper} between the specified values (inclusive). + * @param codepoint + * a Unicode code point + * @return The hex string for the given codepoint * - * @param codepointLow above which to escape - * @param codepointHigh below which to escape - * @return The newly created {@code UnicodeEscaper} instance */ - public static UnicodeEscaper between(final int codepointLow, final int codepointHigh) { - return new UnicodeEscaper(codepointLow, codepointHigh, true); + protected String toUtf16Escape(final int codepoint) { + return "\\u" + hex(codepoint); } /** @@ -125,16 +137,4 @@ public class UnicodeEscaper extends CodePointTranslator { } return true; } - - /** - * Converts the given codepoint to a hex string of the form {@code "\\uXXXX"}. - * - * @param codepoint - * a Unicode code point - * @return The hex string for the given codepoint - * - */ - protected String toUtf16Escape(final int codepoint) { - return "\\u" + hex(codepoint); - } }