Skip to content

Commit

Permalink
#107 Improve JavaDoc for Memento example
Browse files Browse the repository at this point in the history
  • Loading branch information
iluwatar committed Aug 19, 2015
1 parent 252f938 commit 8701833
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 67 deletions.
72 changes: 36 additions & 36 deletions memento/src/main/java/com/iluwatar/memento/App.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package com.iluwatar.memento;

import java.util.Stack;

/**
*
* Memento pattern is for storing and restoring object state. The object (Star)
* gives out a "memento" (StarMemento) that contains the state of the object.
* Later on the memento can be set back to the object restoring the state.
*
*/
public class App {

public static void main(String[] args) {
Stack<StarMemento> states = new Stack<>();

Star star = new Star(StarType.SUN, 10000000, 500000);
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
while (states.size() > 0) {
star.setMemento(states.pop());
System.out.println(star);
}
}
}
package com.iluwatar.memento;

import java.util.Stack;

/**
*
* Memento pattern is for storing and restoring object state. The object ({@link Star})
* 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.
*
*/
public class App {

public static void main(String[] args) {
Stack<StarMemento> states = new Stack<>();

Star star = new Star(StarType.SUN, 10000000, 500000);
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
states.add(star.getMemento());
star.timePasses();
System.out.println(star);
while (states.size() > 0) {
star.setMemento(states.pop());
System.out.println(star);
}
}
}
39 changes: 22 additions & 17 deletions memento/src/main/java/com/iluwatar/memento/StarType.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.iluwatar.memento;

public enum StarType {

SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED("");

private String title;

StarType(String title) {
this.title = title;
}

@Override
public String toString() {
return title;
}
}
package com.iluwatar.memento;

/**
*
* StarType enumeration
*
*/
public enum StarType {

SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD("dead star"), UNDEFINED("");

private String title;

StarType(String title) {
this.title = title;
}

@Override
public String toString() {
return title;
}
}
33 changes: 19 additions & 14 deletions memento/src/test/java/com/iluwatar/memento/AppTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.iluwatar.memento;

import org.junit.Test;

import com.iluwatar.memento.App;

public class AppTest {

@Test
public void test() {
String[] args = {};
App.main(args);
}
}
package com.iluwatar.memento;

import org.junit.Test;

import com.iluwatar.memento.App;

/**
*
* Application test
*
*/
public class AppTest {

@Test
public void test() {
String[] args = {};
App.main(args);
}
}

0 comments on commit 8701833

Please sign in to comment.