новый компонент: Text
This commit is contained in:
@@ -5,9 +5,11 @@ import lombok.Setter;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Accessors(fluent = true)
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ToString
|
@ToString
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
lombok.accessors.fluent=true
|
|
||||||
46
protocol/src/main/java/mc/protocol/model/text/Text.java
Normal file
46
protocol/src/main/java/mc/protocol/model/text/Text.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package mc.protocol.model.text;
|
||||||
|
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString
|
||||||
|
public class Text {
|
||||||
|
|
||||||
|
public static final Text EMPTY = of("");
|
||||||
|
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
Text(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Text of(String content) {
|
||||||
|
return new Text(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Text.Builder builder() {
|
||||||
|
return new Text.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
public Builder append(String content) {
|
||||||
|
if (this.content == null) {
|
||||||
|
this.content = content;
|
||||||
|
} else {
|
||||||
|
this.content += content;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text build() {
|
||||||
|
if (content == null) {
|
||||||
|
return EMPTY;
|
||||||
|
} else {
|
||||||
|
return new Text(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
protocol/src/test/java/mc/protocol/model/text/TextTest.java
Normal file
30
protocol/src/test/java/mc/protocol/model/text/TextTest.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package mc.protocol.model.text;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class TextTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void emptyTest() {
|
||||||
|
Text actual = Text.builder().build();
|
||||||
|
Text expected = Text.EMPTY;
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contentTest() {
|
||||||
|
Text actual;
|
||||||
|
Text expected;
|
||||||
|
|
||||||
|
actual = Text.builder().append("123").build();
|
||||||
|
expected = new Text("123");
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
|
||||||
|
actual = Text.builder().append("123").append("456").build();
|
||||||
|
expected = new Text("123456");
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user