[BAEL-3090] Added test + removed cursor
This commit is contained in:
parent
dd7b922f2b
commit
83d8443fef
|
@ -31,6 +31,12 @@
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${commons-lang3.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -38,5 +44,6 @@
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<intellij.annotations.version>16.0.2</intellij.annotations.version>
|
<intellij.annotations.version>16.0.2</intellij.annotations.version>
|
||||||
|
<assertj.version>3.12.2</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -9,6 +9,14 @@ public class TextEditor {
|
||||||
this.textWindow = textWindow;
|
this.textWindow = textWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void write(String text) {
|
||||||
|
textWindow.addText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String print() {
|
||||||
|
return textWindow.getCurrentText();
|
||||||
|
}
|
||||||
|
|
||||||
public void hitSave() {
|
public void hitSave() {
|
||||||
savedTextWindow = textWindow.save();
|
savedTextWindow = textWindow.save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,13 @@ package com.baeldung.memento;
|
||||||
public class TextWindow {
|
public class TextWindow {
|
||||||
|
|
||||||
private StringBuilder currentText;
|
private StringBuilder currentText;
|
||||||
private Coordinates cursorPosition;
|
|
||||||
|
|
||||||
public TextWindow() {
|
public TextWindow() {
|
||||||
this.currentText = new StringBuilder();
|
this.currentText = new StringBuilder();
|
||||||
this.cursorPosition = new Coordinates(0, 0);
|
}
|
||||||
|
|
||||||
|
public String getCurrentText() {
|
||||||
|
return currentText.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addText(String text) {
|
public void addText(String text) {
|
||||||
|
@ -20,11 +22,5 @@ public class TextWindow {
|
||||||
|
|
||||||
public void restore(TextWindowState save) {
|
public void restore(TextWindowState save) {
|
||||||
currentText = new StringBuilder(save.getText());
|
currentText = new StringBuilder(save.getText());
|
||||||
cursorPosition = atTextEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Coordinates atTextEnd() {
|
|
||||||
String[] lines = currentText.toString().split("\n");
|
|
||||||
return new Coordinates(lines[lines.length - 1].length(), lines.length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue