Java 11 migraiton: memento
This commit is contained in:
parent
93e5570778
commit
a00622c656
@ -52,9 +52,9 @@ public class App {
|
|||||||
* Program entry point.
|
* Program entry point.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Stack<StarMemento> states = new Stack<>();
|
var states = new Stack<StarMemento>();
|
||||||
|
|
||||||
Star star = new Star(StarType.SUN, 10000000, 500000);
|
var star = new Star(StarType.SUN, 10000000, 500000);
|
||||||
LOGGER.info(star.toString());
|
LOGGER.info(star.toString());
|
||||||
states.add(star.getMemento());
|
states.add(star.getMemento());
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
|
@ -71,7 +71,7 @@ public class Star {
|
|||||||
|
|
||||||
StarMemento getMemento() {
|
StarMemento getMemento() {
|
||||||
|
|
||||||
StarMementoInternal state = new StarMementoInternal();
|
var state = new StarMementoInternal();
|
||||||
state.setAgeYears(ageYears);
|
state.setAgeYears(ageYears);
|
||||||
state.setMassTons(massTons);
|
state.setMassTons(massTons);
|
||||||
state.setType(type);
|
state.setType(type);
|
||||||
@ -81,7 +81,7 @@ public class Star {
|
|||||||
|
|
||||||
void setMemento(StarMemento memento) {
|
void setMemento(StarMemento memento) {
|
||||||
|
|
||||||
StarMementoInternal state = (StarMementoInternal) memento;
|
var state = (StarMementoInternal) memento;
|
||||||
this.type = state.getType();
|
this.type = state.getType();
|
||||||
this.ageYears = state.getAgeYears();
|
this.ageYears = state.getAgeYears();
|
||||||
this.massTons = state.getMassTons();
|
this.massTons = state.getMassTons();
|
||||||
|
@ -31,7 +31,7 @@ public enum StarType {
|
|||||||
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD(
|
SUN("sun"), RED_GIANT("red giant"), WHITE_DWARF("white dwarf"), SUPERNOVA("supernova"), DEAD(
|
||||||
"dead star"), UNDEFINED("");
|
"dead star"), UNDEFINED("");
|
||||||
|
|
||||||
private String title;
|
private final String title;
|
||||||
|
|
||||||
StarType(String title) {
|
StarType(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
@ -26,15 +26,12 @@ package com.iluwatar.memento;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Application test
|
* Application test
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
String[] args = {};
|
App.main(new String[]{});
|
||||||
App.main(args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
|
|
||||||
package com.iluwatar.memento;
|
package com.iluwatar.memento;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date: 12/20/15 - 10:08 AM
|
* Date: 12/20/15 - 10:08 AM
|
||||||
*
|
*
|
||||||
@ -39,7 +39,7 @@ public class StarTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTimePasses() {
|
public void testTimePasses() {
|
||||||
final Star star = new Star(StarType.SUN, 1, 2);
|
final var star = new Star(StarType.SUN, 1, 2);
|
||||||
assertEquals("sun age: 1 years mass: 2 tons", star.toString());
|
assertEquals("sun age: 1 years mass: 2 tons", star.toString());
|
||||||
|
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
@ -66,16 +66,16 @@ public class StarTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetMemento() {
|
public void testSetMemento() {
|
||||||
final Star star = new Star(StarType.SUN, 1, 2);
|
final var star = new Star(StarType.SUN, 1, 2);
|
||||||
final StarMemento firstMemento = star.getMemento();
|
final var firstMemento = star.getMemento();
|
||||||
assertEquals("sun age: 1 years mass: 2 tons", star.toString());
|
assertEquals("sun age: 1 years mass: 2 tons", star.toString());
|
||||||
|
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
final StarMemento secondMemento = star.getMemento();
|
final var secondMemento = star.getMemento();
|
||||||
assertEquals("red giant age: 2 years mass: 16 tons", star.toString());
|
assertEquals("red giant age: 2 years mass: 16 tons", star.toString());
|
||||||
|
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
final StarMemento thirdMemento = star.getMemento();
|
final var thirdMemento = star.getMemento();
|
||||||
assertEquals("white dwarf age: 4 years mass: 128 tons", star.toString());
|
assertEquals("white dwarf age: 4 years mass: 128 tons", star.toString());
|
||||||
|
|
||||||
star.timePasses();
|
star.timePasses();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user