-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#107 Improve JavaDoc for Memento example
- Loading branch information
Showing
3 changed files
with
77 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |