This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit e7de3e0cce647c5a06cfe81fa3443b7a90cce023 Author: Martin Desruisseaux <[email protected]> AuthorDate: Sun Mar 10 14:55:33 2019 +0100 Share the CONTINUATION_MARK and CONTINUATION_END characters. --- .../java/org/apache/sis/internal/util/Strings.java | 9 +++++++-- .../apache/sis/util/logging/MonolineFormatter.java | 19 ++++++++----------- .../sis/util/logging/MonolineFormatterTest.java | 5 +++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java index 19b4cef..ed87ddb 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java +++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/Strings.java @@ -35,6 +35,11 @@ import org.apache.sis.util.CharSequences; */ public final class Strings extends Static { /** + * The character to write at the beginning of lines that are continuation of a single log record. + */ + public static final char CONTINUATION_MARK = '┃', CONTINUATION_END = '╹'; + + /** * Do not allow instantiation of this class. */ private Strings() { @@ -192,11 +197,11 @@ public final class Strings extends Static { * @param lineSeparator the line separator. */ public static void insertLineInLeftMargin(final StringBuilder buffer, final String lineSeparator) { - char c = '╹'; + char c = CONTINUATION_END; int i = CharSequences.skipTrailingWhitespaces(buffer, 0, buffer.length()); while ((i = buffer.lastIndexOf(lineSeparator, i - 1)) >= 0) { buffer.insert(i + lineSeparator.length(), c); - c = '┃'; + c = CONTINUATION_MARK; } } diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java b/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java index e5fe846..a69c3d5 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java +++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java @@ -35,6 +35,7 @@ import java.util.logging.*; import org.apache.sis.internal.system.Modules; import org.apache.sis.internal.system.OS; import org.apache.sis.internal.util.X364; +import org.apache.sis.internal.util.Strings; import org.apache.sis.internal.util.AutoMessageFormat; import org.apache.sis.io.IO; import org.apache.sis.io.LineAppender; @@ -167,17 +168,12 @@ public class MonolineFormatter extends Formatter { /** * Number of characters or spaces to colorize at the beginning of lines that are continuation of a single log record. - * This count includes the {@link #CONTINUATION_MARK} character. Should not be smaller than 2 since the algorithm in - * this class needs one white space after {@link #CONTINUATION_MARK}. + * This count includes the {@link Strings#CONTINUATION_MARK} character. Should not be smaller than 2 since algorithm + * in this class needs one white space after {@link Strings#CONTINUATION_MARK}. */ private static final int CONTINUATION_MARGIN = 4; /** - * The character to write at the beginning of lines that are continuation of a single log record. - */ - static final char CONTINUATION_MARK = '┃', CONTINUATION_END = '╹'; - - /** * Minimal number of stack trace elements to print before and after the "interesting" elements. * The "interesting" elements are the first stack trace elements, and the element which point * to the method that produced the log record. @@ -736,8 +732,9 @@ loop: for (int i=0; ; i++) { if (bodyLineSeparator.length() != lineSeparator.length() + margin + 1) { if (CONTINUATION_MARGIN != 0) { final int highlight = Math.min(CONTINUATION_MARGIN, margin); - bodyLineSeparator = lineSeparator + levelColor + CONTINUATION_MARK + CharSequences.spaces(highlight - 1) - + levelReset + CharSequences.spaces(margin - highlight + 1); + bodyLineSeparator = lineSeparator + + levelColor + Strings.CONTINUATION_MARK + CharSequences.spaces(highlight - 1) + + levelReset + CharSequences.spaces(margin - highlight + 1); } else { bodyLineSeparator = lineSeparator; } @@ -797,11 +794,11 @@ loop: for (int i=0; ; i++) { * If the message spans more than one line, there is CONTINUATION_MARK characters in the * margin. Replace the last occurrence of those characters by CONTINUATION_END. */ - lastMargin = CharSequences.indexOf(buffer, CONTINUATION_MARK, + lastMargin = CharSequences.indexOf(buffer, Strings.CONTINUATION_MARK, lastMargin + lineSeparator.length(), lastMargin + bodyLineSeparator.length()); if (lastMargin >= 0) { - buffer.setCharAt(lastMargin, CONTINUATION_END); + buffer.setCharAt(lastMargin, Strings.CONTINUATION_END); } return buffer.append(lineSeparator).toString(); } diff --git a/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java b/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java index 5613336..91d5998 100644 --- a/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java +++ b/core/sis-utility/src/test/java/org/apache/sis/util/logging/MonolineFormatterTest.java @@ -18,6 +18,7 @@ package org.apache.sis.util.logging; import java.util.logging.Level; import java.util.logging.LogRecord; +import org.apache.sis.internal.util.Strings; import org.apache.sis.util.CharSequences; import org.apache.sis.test.DependsOnMethod; import org.apache.sis.test.TestCase; @@ -66,14 +67,14 @@ public final strictfp class MonolineFormatterTest extends TestCase { .append(levelLocalized) .append(CharSequences.spaces(margin - levelLocalized.length())) .append(expected, levelToReplace.length() + 1, expected.length()); // +1 is for skipping '\t'. - final String spaces = MonolineFormatter.CONTINUATION_MARK + final String spaces = Strings.CONTINUATION_MARK + CharSequences.spaces(margin - 1).toString(); int positionOfLast = -1; for (int i=margin; (i=buffer.indexOf("\n\t", i)) >= 0; i += margin) { buffer.replace(positionOfLast = ++i, i+1, spaces); // Replace only tabulation, leave new line. } if (positionOfLast >= 0) { - buffer.setCharAt(positionOfLast, MonolineFormatter.CONTINUATION_END); + buffer.setCharAt(positionOfLast, Strings.CONTINUATION_END); } return buffer.toString(); }
