#107 Improve JavaDoc for Memento example

This commit is contained in:
Ilkka Seppala 2015-08-19 22:13:40 +03:00
parent 252f93899f
commit 8701833d83
3 changed files with 77 additions and 67 deletions

View File

@ -1,36 +1,36 @@
package com.iluwatar.memento; package com.iluwatar.memento;
import java.util.Stack; import java.util.Stack;
/** /**
* *
* Memento pattern is for storing and restoring object state. The object (Star) * Memento pattern is for storing and restoring object state. The object ({@link Star})
* gives out a "memento" (StarMemento) that contains the state of the object. * gives out a "memento" ({@link StarMemento}) that contains the state of the object.
* Later on the memento can be set back to the object restoring the state. * Later on the memento can be set back to the object restoring the state.
* *
*/ */
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
Stack<StarMemento> states = new Stack<>(); Stack<StarMemento> states = new Stack<>();
Star star = new Star(StarType.SUN, 10000000, 500000); Star star = new Star(StarType.SUN, 10000000, 500000);
System.out.println(star); System.out.println(star);
states.add(star.getMemento()); states.add(star.getMemento());
star.timePasses(); star.timePasses();
System.out.println(star); System.out.println(star);
states.add(star.getMemento()); states.add(star.getMemento());
star.timePasses(); star.timePasses();
System.out.println(star); System.out.println(star);
states.add(star.getMemento()); states.add(star.getMemento());
star.timePasses(); star.timePasses();
System.out.println(star); System.out.println(star);
states.add(star.getMemento()); states.add(star.getMemento());
star.timePasses(); star.timePasses();
System.out.println(star); System.out.println(star);
while (states.size() > 0) { while (states.size() > 0) {
star.setMemento(states.pop()); star.setMemento(states.pop());
System.out.println(star); System.out.println(star);
} }
} }
} }

View File

@ -1,17 +1,22 @@
package com.iluwatar.memento; package com.iluwatar.memento;
public enum StarType { /**
*
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED(""); * StarType enumeration
*
private String title; */
public enum StarType {
StarType(String title) {
this.title = title; SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED("");
}
private String title;
@Override
public String toString() { StarType(String title) {
return title; this.title = title;
} }
}
@Override
public String toString() {
return title;
}
}

View File

@ -1,14 +1,19 @@
package com.iluwatar.memento; package com.iluwatar.memento;
import org.junit.Test; import org.junit.Test;
import com.iluwatar.memento.App; import com.iluwatar.memento.App;
public class AppTest { /**
*
@Test * Application test
public void test() { *
String[] args = {}; */
App.main(args); public class AppTest {
}
} @Test
public void test() {
String[] args = {};
App.main(args);
}
}