Przeglądaj źródła

Rename Card -> Phase

Sam Jaffe 5 lat temu
rodzic
commit
af1a2195b6

+ 1 - 1
src/main/lombok/org/leumasjaffe/recipe/model/Card.java

@@ -12,7 +12,7 @@ import lombok.EqualsAndHashCode;
 import lombok.NonNull;
 
 @Data @EqualsAndHashCode(callSuper=false)
-public class Card extends Observable.Instance implements CompoundRecipeComponent {	
+public class Phase extends Observable.Instance implements CompoundRecipeComponent {	
 	int id = 0; // TODO Fix this
 	int[] dependsOn = {}; // decltype(id)[]
 	String vessel = "";

+ 4 - 4
src/main/lombok/org/leumasjaffe/recipe/model/Product.java

@@ -11,16 +11,16 @@ import lombok.EqualsAndHashCode;
 @Data @EqualsAndHashCode(callSuper=false)
 public class Product extends Observable.Instance implements CompoundRecipeComponent {
 	String name;
-	List<Card> cards;
+	List<Phase> phases;
 
 	@Override
 	public Stream<Ingredient> getIngredientsAsStream() {
-		return getComponents().flatMap(Card::getIngredientsAsStream)
+		return getComponents().flatMap(Phase::getIngredientsAsStream)
 				.map(i -> new Ingredient(i.getName(), "", i.getAmount()));
 	}
 
 	@Override
-	public Stream<Card> getComponents() {
-		return cards.stream();
+	public Stream<Phase> getComponents() {
+		return phases.stream();
 	}	
 }

+ 8 - 8
src/main/lombok/org/leumasjaffe/recipe/view/CardPanel.java

@@ -4,7 +4,7 @@ import javax.swing.JPanel;
 
 import org.leumasjaffe.observer.ForwardingObservableListener;
 import org.leumasjaffe.observer.ObserverDispatch;
-import org.leumasjaffe.recipe.model.Card;
+import org.leumasjaffe.recipe.model.Phase;
 import org.leumasjaffe.recipe.model.Preparation;
 import org.leumasjaffe.recipe.model.Rest;
 import org.leumasjaffe.recipe.model.Step;
@@ -17,17 +17,17 @@ import org.jdesktop.swingx.VerticalLayout;
 
 @SuppressWarnings("serial")
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
-public class CardPanel extends JPanel {
+public class PhasePanel extends JPanel {
 	@NonFinal int steps = 0;
-	ForwardingObservableListener<Card> listener = new ForwardingObservableListener<>();
+	ForwardingObservableListener<Phase> listener = new ForwardingObservableListener<>();
 
-	public CardPanel(final Card card) {		
+	public PhasePanel(final Phase phase) {		
 		setLayout(new VerticalLayout(5));
 		
-		card.getPreparation().ifPresent(this::addPrep);
-		card.getCooking().forEach(this::addStep);
-		card.getRest().ifPresent(this::addRest);
-		listener.setObserved(card, card.getCooking());
+		phase.getPreparation().ifPresent(this::addPrep);
+		phase.getCooking().forEach(this::addStep);
+		phase.getRest().ifPresent(this::addRest);
+		listener.setObserved(phase, phase.getCooking());
 	}
 	
 	void addPrep(final Preparation step) {

+ 5 - 5
src/main/lombok/org/leumasjaffe/recipe/view/ProductPanel.java

@@ -5,7 +5,7 @@ import javax.swing.JScrollPane;
 
 import org.leumasjaffe.observer.ForwardingObservableListener;
 import org.leumasjaffe.observer.ObserverDispatch;
-import org.leumasjaffe.recipe.model.Card;
+import org.leumasjaffe.recipe.model.Phase;
 import org.leumasjaffe.recipe.model.Product;
 
 import lombok.AccessLevel;
@@ -26,19 +26,19 @@ public class ProductPanel extends JScrollPane {
 		JPanel panelColumnHeader = new JPanel();
 		setColumnHeaderView(panelColumnHeader);
 		
-		JButton btnAddStep = new JButton("Add Card");
+		JButton btnAddStep = new JButton("Add Phase");
 		panelColumnHeader.add(btnAddStep);
 		
 		panelViewPort = new JPanel();
 		setViewportView(panelViewPort);
 		panelViewPort.setLayout(new VerticalLayout(5));
 				
-		for (final Card card : product.getCards()) {
-			panelViewPort.add(new CardPanel(card));
+		for (final Phase phase : product.getPhases()) {
+			panelViewPort.add(new PhasePanel(phase));
 			panelViewPort.add(new JSeparator());
 		}
 		
-		listener.setObserved(product, product.getCards());
+		listener.setObserved(product, product.getPhases());
 	}
 	
 	@Override

+ 26 - 26
src/test/java/org/leumasjaffe/recipe/model/CardTest.java

@@ -10,84 +10,84 @@ import java.util.Optional;
 
 import org.junit.jupiter.api.Test;
 
-class CardTest {
+class PhaseTest {
 	private static final Amount _1g = new Amount("1 g");
 	private static final Duration dur = new Duration(Duration.Display.SECONDS, false, 10, 20);
 
 	@Test
 	void cannotAddNullPreparation() {
-		final Card card = new Card();
-		assertThrows(NullPointerException.class, () -> card.setPreparation(null));
+		final Phase phase = new Phase();
+		assertThrows(NullPointerException.class, () -> phase.setPreparation(null));
 	}
 	
 	@Test
 	void testDurationIsZeroByDefault() {
-		final Card card = new Card();
-		assertEquals(Duration.ZERO, card.getDuration());
+		final Phase phase = new Phase();
+		assertEquals(Duration.ZERO, phase.getDuration());
 	}
 	
 	@Test
 	void testSumsTogetherStepDurations() {
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Step step = new Step();
 		step.setDuration(dur);
-		card.setCooking(Arrays.asList(step, step));
+		phase.setCooking(Arrays.asList(step, step));
 		assertEquals(new Duration(Duration.Display.SECONDS, false, 20, 40),
-				card.getDuration());
+				phase.getDuration());
 	}
 	
 	@Test
 	void testDoesNotAddPrepDurationIfPresent() {
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Preparation prep = new Preparation();
 		prep.setDuration(dur);
-		card.setPreparation(prep);
-		assertEquals(Duration.ZERO, card.getDuration());
+		phase.setPreparation(prep);
+		assertEquals(Duration.ZERO, phase.getDuration());
 	}
 	
 	@Test
 	void testDoesNotAddRestDurationIfPresent() {
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Rest rest = new Rest();
 		rest.setWhere(Rest.Where.REFRIGERATOR);
 		rest.setDuration(dur);
-		card.setRest(Optional.of(rest));
-		assertEquals(Duration.ZERO, card.getDuration());
+		phase.setRest(Optional.of(rest));
+		assertEquals(Duration.ZERO, phase.getDuration());
 	}
 
 	@Test
 	void testMergesLikeIngredients() {
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Step step = new Step();
 		step.setIngredients(Arrays.asList(new Ingredient("TEST", "", _1g)));
-		card.setCooking(Arrays.asList(step, step));
-		assertThat(card.getIngredients(), hasSize(1));
-		assertThat(card.getIngredients(),
+		phase.setCooking(Arrays.asList(step, step));
+		assertThat(phase.getIngredients(), hasSize(1));
+		assertThat(phase.getIngredients(),
 				hasItem(new Ingredient("TEST", "", new Amount("2 g"))));
 	}
 
 	@Test
 	void testDoesNotMergeIngredientsWithDifferentPrep() {
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Step step = new Step();
 		step.setIngredients(Arrays.asList(
 				new Ingredient("TEST", "A", _1g),
 				new Ingredient("TEST", "B", _1g)));
-		card.setCooking(Arrays.asList(step));
-		assertThat(card.getIngredients(), hasSize(2));
+		phase.setCooking(Arrays.asList(step));
+		assertThat(phase.getIngredients(), hasSize(2));
 	}
 
 	@Test
 	void testPrepIngredientsAreCardIngredientsWithPrep() {
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Step step = new Step();
 		step.setIngredients(Arrays.asList(
 				new Ingredient("A", "", _1g),
 				new Ingredient("B", "TEST", _1g)));
-		card.setCooking(Arrays.asList(step));
-		card.setPreparation(new Preparation());
-		assertThat(card.getIngredients(), hasSize(2));
-		final Preparation prep = card.getPreparation().get();
+		phase.setCooking(Arrays.asList(step));
+		phase.setPreparation(new Preparation());
+		assertThat(phase.getIngredients(), hasSize(2));
+		final Preparation prep = phase.getPreparation().get();
 		assertThat(prep.getIngredients(), hasSize(1));
 		assertThat(prep.getIngredients(), hasItem(new Ingredient("B", "TEST", _1g)));
 	}

+ 3 - 3
src/test/java/org/leumasjaffe/recipe/model/ProductTest.java

@@ -14,13 +14,13 @@ class ProductTest {
 	@Test
 	void testMergesIngredientsWithDifferentPrep() {
 		final Product prod = new Product();
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Step step = new Step();
 		step.setIngredients(Arrays.asList(
 				new Ingredient("TEST", "A", _1g),
 				new Ingredient("TEST", "B", _1g)));
-		card.setCooking(Arrays.asList(step));
-		prod.setCards(Arrays.asList(card));
+		phase.setCooking(Arrays.asList(step));
+		prod.setPhases(Arrays.asList(phase));
 		assertThat(prod.getIngredients(), hasSize(1));
 		assertThat(prod.getIngredients(),
 				hasItem(new Ingredient("TEST", "", new Amount("2 g"))));

+ 3 - 3
src/test/java/org/leumasjaffe/recipe/model/RecipeTest.java

@@ -15,13 +15,13 @@ class RecipeTest {
 	void testMergesIngredientsWithDifferentPrep() {
 		final Recipe recipe = new Recipe();
 		final Product prod = new Product();
-		final Card card = new Card();
+		final Phase phase = new Phase();
 		final Step step = new Step();
 		step.setIngredients(Arrays.asList(
 				new Ingredient("TEST", "A", _1g),
 				new Ingredient("TEST", "B", _1g)));
-		card.setCooking(Arrays.asList(step));
-		prod.setCards(Arrays.asList(card));
+		phase.setCooking(Arrays.asList(step));
+		prod.setPhases(Arrays.asList(phase));
 		recipe.setProducts(Arrays.asList(prod, prod));
 		assertThat(recipe.getIngredients(), hasSize(1));
 		assertThat(recipe.getIngredients(),

+ 5 - 5
src/test/java/org/leumasjaffe/recipe/view/CardPanelTest.java

@@ -11,7 +11,7 @@ import org.junit.platform.runner.JUnitPlatform;
 import org.junit.runner.RunWith;
 import org.leumasjaffe.mock.MockObserverListener;
 import org.leumasjaffe.observer.ObserverDispatch;
-import org.leumasjaffe.recipe.model.Card;
+import org.leumasjaffe.recipe.model.Phase;
 import org.leumasjaffe.recipe.model.Step;
 import org.mockito.Mock;
 import org.mockito.Spy;
@@ -19,17 +19,17 @@ import org.mockito.junit.jupiter.MockitoExtension;
 
 @ExtendWith(MockitoExtension.class)
 @RunWith(JUnitPlatform.class)
-class CardPanelTest extends SwingTestCase {
+class PhasePanelTest extends SwingTestCase {
 	
 	@Spy MockObserverListener listener;
 	final Step stub = new Step();
-	@Mock Card stuff;
-	CardPanel panel;
+	@Mock Phase stuff;
+	PhasePanel panel;
 
 	@BeforeEach
 	void setUp() {
 		doReturn(Arrays.asList(stub)).when(stuff).getCooking();
-		panel = new CardPanel(stuff);
+		panel = new PhasePanel(stuff);
 		
 		listener.setObserved(stuff);
 		// setObserved() calls update

+ 3 - 3
src/test/java/org/leumasjaffe/recipe/view/ProductPanelTest.java

@@ -11,7 +11,7 @@ import org.junit.platform.runner.JUnitPlatform;
 import org.junit.runner.RunWith;
 import org.leumasjaffe.mock.MockObserverListener;
 import org.leumasjaffe.observer.ObserverDispatch;
-import org.leumasjaffe.recipe.model.Card;
+import org.leumasjaffe.recipe.model.Phase;
 import org.leumasjaffe.recipe.model.Product;
 import org.mockito.Mock;
 import org.mockito.Spy;
@@ -22,13 +22,13 @@ import org.mockito.junit.jupiter.MockitoExtension;
 class ProductPanelTest extends SwingTestCase {
 	
 	@Spy MockObserverListener listener;
-	final Card stub = new Card();
+	final Phase stub = new Phase();
 	@Mock Product stuff;
 	ProductPanel panel;
 
 	@BeforeEach
 	void setUp() {
-		doReturn(Arrays.asList(stub)).when(stuff).getCards();
+		doReturn(Arrays.asList(stub)).when(stuff).getPhases();
 		panel = new ProductPanel(stuff);
 		
 		listener.setObserved(stuff);

+ 2 - 2
src/test/resources/example.json

@@ -4,7 +4,7 @@
   "products": [
     {
       "name": "Curry",
-      "cards": [
+      "phases": [
         {
           "id": 0,
           "dependsOn": [],
@@ -56,7 +56,7 @@
             "duration": {
               "displayAs": "SECONDS",
               "approximate": false,
-              "minSeconds": 30,
+              "minSeconds": 0,
               "maxSeconds": 30
             }
           }