#107 Improve JavaDoc for Memento example
This commit is contained in:
		@@ -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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user