Skip to content

Commit cc9042c

Browse files
committed
Normalize builder pattern
1 parent a33b329 commit cc9042c

2 files changed

Lines changed: 20 additions & 35 deletions

File tree

src/main/java/org/apache/commons/cli/help/TextHelpAppendable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected TableDefinition adjustTableFormat(final TableDefinition table) {
150150
final List<TextStyle.Builder> styleBuilders = new ArrayList<>();
151151
for (int i = 0; i < table.columnTextStyles().size(); i++) {
152152
final TextStyle style = table.columnTextStyles().get(i);
153-
final TextStyle.Builder builder = TextStyle.builder(style);
153+
final TextStyle.Builder builder = TextStyle.builder().setTextStyle(style);
154154
styleBuilders.add(builder);
155155
final String header = table.headers().get(i);
156156

@@ -245,7 +245,7 @@ public void appendTable(final TableDefinition rawTable) throws IOException {
245245
appendParagraph(table.caption());
246246
final List<TextStyle> headerStyles = new ArrayList<>();
247247
for (final TextStyle style : table.columnTextStyles()) {
248-
headerStyles.add(TextStyle.builder(style).setAlignment(TextStyle.Alignment.CENTER).get());
248+
headerStyles.add(TextStyle.builder().setTextStyle(style).setAlignment(TextStyle.Alignment.CENTER).get());
249249
}
250250
writeColumnQueues(makeColumnQueues(table.headers(), headerStyles), headerStyles);
251251
for (final List<String> row : table.rows()) {

src/main/java/org/apache/commons/cli/help/TextStyle.java

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2727
*/
2828
public final class TextStyle {
2929

30-
/**
30+
/**
3131
* The alignment possibilities.
3232
*/
3333
public enum Alignment {
@@ -91,28 +91,6 @@ public static final class Builder implements Supplier<TextStyle> {
9191
private Builder() {
9292
}
9393

94-
/**
95-
* Constructs a builder from an existing TextStyle. The default values are:
96-
* <ul>
97-
* <li>alignment = LEFT</li>
98-
* <li>leftPad = 0</li>
99-
* <li>scaling = VARIABLE</li>
100-
* <li>minWidth = 0</li>
101-
* <li>maxWidth = UNSET_MAX_WIDTH</li>
102-
* </ul>
103-
* *
104-
*
105-
* @param style the TextStyle to set all values from.
106-
*/
107-
private Builder(final TextStyle style) {
108-
this.alignment = style.alignment;
109-
this.leftPad = style.leftPad;
110-
this.indent = style.indent;
111-
this.scalable = style.scalable;
112-
this.minWidth = style.minWidth;
113-
this.maxWidth = style.maxWidth;
114-
}
115-
11694
@Override
11795
public TextStyle get() {
11896
return new TextStyle(this);
@@ -228,6 +206,23 @@ public Builder setScalable(final boolean scalable) {
228206
this.scalable = scalable;
229207
return this;
230208
}
209+
210+
/**
211+
* Sets all properties from the given text style.
212+
*
213+
* @param style the source text style.
214+
* @return this instance.
215+
*/
216+
public Builder setTextStyle(final TextStyle style) {
217+
this.alignment = style.alignment;
218+
this.leftPad = style.leftPad;
219+
this.indent = style.indent;
220+
this.scalable = style.scalable;
221+
this.minWidth = style.minWidth;
222+
this.maxWidth = style.maxWidth;
223+
return this;
224+
}
225+
231226
}
232227

233228
/**
@@ -249,16 +244,6 @@ public static Builder builder() {
249244
return new Builder();
250245
}
251246

252-
/**
253-
* Creates a new builder.
254-
*
255-
* @param textStyle The new builder values are copied from the given TextStyle.
256-
* @return a new builder.
257-
*/
258-
public static Builder builder(final TextStyle textStyle) {
259-
return new Builder(textStyle);
260-
}
261-
262247
/** The alignment. */
263248
private final Alignment alignment;
264249

0 commit comments

Comments
 (0)