Text: дополнен children
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package mc.protocol.model.text;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -10,13 +11,15 @@ public class Text {
|
||||
public static final Text EMPTY = of("");
|
||||
|
||||
private String content;
|
||||
private ImmutableList<Text> children;
|
||||
|
||||
Text(String content) {
|
||||
Text(String content, ImmutableList<Text> children) {
|
||||
this.content = content;
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public static Text of(String content) {
|
||||
return new Text(content);
|
||||
return new Text(content, null);
|
||||
}
|
||||
|
||||
public static Text.Builder builder() {
|
||||
@@ -25,6 +28,7 @@ public class Text {
|
||||
|
||||
public static class Builder {
|
||||
private String content;
|
||||
private ImmutableList.Builder<Text> childrenBuilder;
|
||||
|
||||
public Builder append(String content) {
|
||||
if (this.content == null) {
|
||||
@@ -35,11 +39,25 @@ public class Text {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder append(Text text) {
|
||||
if (text == null || EMPTY.equals(text)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (this.childrenBuilder == null) {
|
||||
this.childrenBuilder = ImmutableList.builder();
|
||||
}
|
||||
|
||||
this.childrenBuilder.add(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Text build() {
|
||||
if (content == null) {
|
||||
if (content == null && childrenBuilder == null) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
return new Text(content);
|
||||
return new Text(content,
|
||||
childrenBuilder == null ? null : childrenBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user