Skip to content

Commit 8701833

Browse files
committed
iluwatar#107 Improve JavaDoc for Memento example
1 parent 252f938 commit 8701833

File tree

3 files changed

+77
-67
lines changed

3 files changed

+77
-67
lines changed
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
package com.iluwatar.memento;
2-
3-
import java.util.Stack;
4-
5-
/**
6-
*
7-
* Memento pattern is for storing and restoring object state. The object (Star)
8-
* gives out a "memento" (StarMemento) that contains the state of the object.
9-
* Later on the memento can be set back to the object restoring the state.
10-
*
11-
*/
12-
public class App {
13-
14-
public static void main(String[] args) {
15-
Stack<StarMemento> states = new Stack<>();
16-
17-
Star star = new Star(StarType.SUN, 10000000, 500000);
18-
System.out.println(star);
19-
states.add(star.getMemento());
20-
star.timePasses();
21-
System.out.println(star);
22-
states.add(star.getMemento());
23-
star.timePasses();
24-
System.out.println(star);
25-
states.add(star.getMemento());
26-
star.timePasses();
27-
System.out.println(star);
28-
states.add(star.getMemento());
29-
star.timePasses();
30-
System.out.println(star);
31-
while (states.size() > 0) {
32-
star.setMemento(states.pop());
33-
System.out.println(star);
34-
}
35-
}
36-
}
1+
package com.iluwatar.memento;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
*
7+
* Memento pattern is for storing and restoring object state. The object ({@link Star})
8+
* gives out a "memento" ({@link StarMemento}) that contains the state of the object.
9+
* Later on the memento can be set back to the object restoring the state.
10+
*
11+
*/
12+
public class App {
13+
14+
public static void main(String[] args) {
15+
Stack<StarMemento> states = new Stack<>();
16+
17+
Star star = new Star(StarType.SUN, 10000000, 500000);
18+
System.out.println(star);
19+
states.add(star.getMemento());
20+
star.timePasses();
21+
System.out.println(star);
22+
states.add(star.getMemento());
23+
star.timePasses();
24+
System.out.println(star);
25+
states.add(star.getMemento());
26+
star.timePasses();
27+
System.out.println(star);
28+
states.add(star.getMemento());
29+
star.timePasses();
30+
System.out.println(star);
31+
while (states.size() > 0) {
32+
star.setMemento(states.pop());
33+
System.out.println(star);
34+
}
35+
}
36+
}
Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
package com.iluwatar.memento;
2-
3-
public enum StarType {
4-
5-
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED("");
6-
7-
private String title;
8-
9-
StarType(String title) {
10-
this.title = title;
11-
}
12-
13-
@Override
14-
public String toString() {
15-
return title;
16-
}
17-
}
1+
package com.iluwatar.memento;
2+
3+
/**
4+
*
5+
* StarType enumeration
6+
*
7+
*/
8+
public enum StarType {
9+
10+
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED("");
11+
12+
private String title;
13+
14+
StarType(String title) {
15+
this.title = title;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return title;
21+
}
22+
}
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
package com.iluwatar.memento;
2-
3-
import org.junit.Test;
4-
5-
import com.iluwatar.memento.App;
6-
7-
public class AppTest {
8-
9-
@Test
10-
public void test() {
11-
String[] args = {};
12-
App.main(args);
13-
}
14-
}
1+
package com.iluwatar.memento;
2+
3+
import org.junit.Test;
4+
5+
import com.iluwatar.memento.App;
6+
7+
/**
8+
*
9+
* Application test
10+
*
11+
*/
12+
public class AppTest {
13+
14+
@Test
15+
public void test() {
16+
String[] args = {};
17+
App.main(args);
18+
}
19+
}

0 commit comments

Comments
 (0)