Skip to content

Commit 5f88214

Browse files
authored
Update README.md
1 parent 20ee9b2 commit 5f88214

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,41 @@ public class Star {
2828
When the state changes, we add the change to the memento list.
2929

3030
```java
31-
public void setState(StarState state) {
32-
this.state = state;
33-
this.memento.add(this.state);
34-
}
31+
public void setState(StarState state) {
32+
this.state = state;
33+
this.memento.add(this.state);
34+
}
3535
```
3636

3737
Then, we just need to implement the methods to restore, undo and redo:
3838

3939
```java
40-
public void restoreState(int index) {
41-
if (this.memento.isEmpty()) {
42-
return;
43-
}
44-
45-
if (index < 0 || index > this.memento.size() - 1) {
46-
throw new IllegalArgumentException("Invalid index");
47-
}
48-
49-
this.state = this.memento.get(index);
40+
public void restoreState(int index) {
41+
if (this.memento.isEmpty()) {
42+
return;
43+
}
5044

45+
if (index < 0 || index > this.memento.size() - 1) {
46+
throw new IllegalArgumentException("Invalid index");
5147
}
5248

53-
public void undo() {
54-
if (this.memento.isEmpty()) {
55-
return;
56-
}
49+
this.state = this.memento.get(index);
5750

58-
int current = this.memento.indexOf(this.state);
51+
}
5952

60-
if (current == 0) {
61-
return;
62-
}
53+
public void undo() {
54+
if (this.memento.isEmpty()) {
55+
return;
56+
}
6357

64-
this.state = this.memento.get(current - 1);
58+
int current = this.memento.indexOf(this.state);
6559

60+
if (current == 0) {
61+
return;
6662
}
6763

68-
```
64+
this.state = this.memento.get(current - 1);
65+
66+
}
67+
68+
```

0 commit comments

Comments
 (0)