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-cli.git

commit cc9042c28aaf00c6742c67eec10733227acaae6f
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Oct 18 08:38:49 2024 -0400

    Normalize builder pattern
---
 .../commons/cli/help/TextHelpAppendable.java       |  4 +-
 .../org/apache/commons/cli/help/TextStyle.java     | 51 ++++++++--------------
 2 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java 
b/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java
index 575b11aa..2725cff2 100644
--- a/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java
+++ b/src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java
@@ -150,7 +150,7 @@ public class TextHelpAppendable extends 
FilterHelpAppendable {
         final List<TextStyle.Builder> styleBuilders = new ArrayList<>();
         for (int i = 0; i < table.columnTextStyles().size(); i++) {
             final TextStyle style = table.columnTextStyles().get(i);
-            final TextStyle.Builder builder = TextStyle.builder(style);
+            final TextStyle.Builder builder = 
TextStyle.builder().setTextStyle(style);
             styleBuilders.add(builder);
             final String header = table.headers().get(i);
 
@@ -245,7 +245,7 @@ public class TextHelpAppendable extends 
FilterHelpAppendable {
         appendParagraph(table.caption());
         final List<TextStyle> headerStyles = new ArrayList<>();
         for (final TextStyle style : table.columnTextStyles()) {
-            
headerStyles.add(TextStyle.builder(style).setAlignment(TextStyle.Alignment.CENTER).get());
+            
headerStyles.add(TextStyle.builder().setTextStyle(style).setAlignment(TextStyle.Alignment.CENTER).get());
         }
         writeColumnQueues(makeColumnQueues(table.headers(), headerStyles), 
headerStyles);
         for (final List<String> row : table.rows()) {
diff --git a/src/main/java/org/apache/commons/cli/help/TextStyle.java 
b/src/main/java/org/apache/commons/cli/help/TextStyle.java
index 69a6b857..b3ca3121 100644
--- a/src/main/java/org/apache/commons/cli/help/TextStyle.java
+++ b/src/main/java/org/apache/commons/cli/help/TextStyle.java
@@ -27,7 +27,7 @@ import java.util.function.Supplier;
  */
 public final class TextStyle {
 
-    /** 
+    /**
      * The alignment possibilities.
       */
     public enum Alignment {
@@ -91,28 +91,6 @@ public final class TextStyle {
         private Builder() {
         }
 
-        /**
-         * Constructs a builder from an existing TextStyle. The default values 
are:
-         * <ul>
-         * <li>alignment = LEFT</li>
-         * <li>leftPad = 0</li>
-         * <li>scaling = VARIABLE</li>
-         * <li>minWidth = 0</li>
-         * <li>maxWidth = UNSET_MAX_WIDTH</li>
-         * </ul>
-         * *
-         *
-         * @param style the TextStyle to set all values from.
-         */
-        private Builder(final TextStyle style) {
-            this.alignment = style.alignment;
-            this.leftPad = style.leftPad;
-            this.indent = style.indent;
-            this.scalable = style.scalable;
-            this.minWidth = style.minWidth;
-            this.maxWidth = style.maxWidth;
-        }
-
         @Override
         public TextStyle get() {
             return new TextStyle(this);
@@ -228,6 +206,23 @@ public final class TextStyle {
             this.scalable = scalable;
             return this;
         }
+
+        /**
+         * Sets all properties from the given text style.
+         *
+         * @param style the source text style.
+         * @return this instance.
+         */
+        public Builder setTextStyle(final TextStyle style) {
+            this.alignment = style.alignment;
+            this.leftPad = style.leftPad;
+            this.indent = style.indent;
+            this.scalable = style.scalable;
+            this.minWidth = style.minWidth;
+            this.maxWidth = style.maxWidth;
+            return this;
+        }
+
     }
 
     /**
@@ -249,16 +244,6 @@ public final class TextStyle {
         return new Builder();
     }
 
-    /**
-     * Creates a new builder.
-     *
-     * @param textStyle The new builder values are copied from the given 
TextStyle.
-     * @return a new builder.
-     */
-    public static Builder builder(final TextStyle textStyle) {
-        return new Builder(textStyle);
-    }
-
     /** The alignment. */
     private final Alignment alignment;
 

Reply via email to