Skip to content

Commit a709560

Browse files
Refactors using var
1 parent 4b38746 commit a709560

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

memento/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ Let's first define the types of stars we are capable to handle.
3434

3535
```java
3636
public enum StarType {
37-
38-
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD(
39-
"dead star"), UNDEFINED("");
37+
SUN("sun"),
38+
RED_GIANT("red giant"),
39+
WHITE_DWARF("white dwarf"),
40+
SUPERNOVA("supernova"),
41+
DEAD("dead star"),
42+
UNDEFINED("");
4043

4144
private final String title;
4245

@@ -95,17 +98,15 @@ public class Star {
9598
}
9699

97100
StarMemento getMemento() {
98-
99-
StarMementoInternal state = new StarMementoInternal();
101+
var state = new StarMementoInternal();
100102
state.setAgeYears(ageYears);
101103
state.setMassTons(massTons);
102104
state.setType(type);
103105
return state;
104106
}
105107

106108
void setMemento(StarMemento memento) {
107-
108-
StarMementoInternal state = (StarMementoInternal) memento;
109+
var state = (StarMementoInternal) memento;
109110
this.type = state.getType();
110111
this.ageYears = state.getAgeYears();
111112
this.massTons = state.getMassTons();
@@ -152,8 +153,8 @@ public class Star {
152153
And finally here's how we use the mementos to store and restore star states.
153154

154155
```java
155-
Stack<StarMemento> states = new Stack<>();
156-
Star star = new Star(StarType.SUN, 10000000, 500000);
156+
var states = new Stack<>();
157+
var star = new Star(StarType.SUN, 10000000, 500000);
157158
LOGGER.info(star.toString());
158159
states.add(star.getMemento());
159160
star.timePasses();

memento/src/main/java/com/iluwatar/memento/Star.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,18 @@ public void timePasses() {
7070
}
7171

7272
StarMemento getMemento() {
73-
7473
var state = new StarMementoInternal();
7574
state.setAgeYears(ageYears);
7675
state.setMassTons(massTons);
7776
state.setType(type);
7877
return state;
79-
8078
}
8179

8280
void setMemento(StarMemento memento) {
83-
8481
var state = (StarMementoInternal) memento;
8582
this.type = state.getType();
8683
this.ageYears = state.getAgeYears();
8784
this.massTons = state.getMassTons();
88-
8985
}
9086

9187
@Override

memento/src/main/java/com/iluwatar/memento/StarType.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
* StarType enumeration.
2828
*/
2929
public enum StarType {
30-
31-
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD(
32-
"dead star"), UNDEFINED("");
30+
SUN("sun"),
31+
RED_GIANT("red giant"),
32+
WHITE_DWARF("white dwarf"),
33+
SUPERNOVA("supernova"),
34+
DEAD("dead star"),
35+
UNDEFINED("");
3336

3437
private final String title;
3538

0 commit comments

Comments
 (0)