commit fc3709dda759d62d4826d5128182c56db894174b Author: Woody Folsom Date: Tue Mar 6 11:45:35 2012 -0500 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..347bb94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +bin +build +classes +dist +docs +.project +.settings +.classpath diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..6d7fb00 --- /dev/null +++ b/build.xml @@ -0,0 +1,90 @@ + + + simple example build file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/PastelVasco.xml b/data/PastelVasco.xml new file mode 100644 index 0000000..6bc4ca4 --- /dev/null +++ b/data/PastelVasco.xml @@ -0,0 +1,123 @@ + + + + + Gateau Basque / Pastel Vasco + + Unai Garro + + + Desserts + Sweets + + 4 + + + + + + + + 185 + grams + + butter + + + + + 425 + grams + + flour + + + + + 250 + grams + + sugar + + + + + 7 + + + egg yolks + + + + + 1 + + + eggs + + + + + 300 + grams + + icing sugar + + + + + 1 + stick + + cinnamon + + + + + 1 + + + vanilla pods + + + + + 100 + grams + + almonds + + + + + 100 + grams + + currants + + + + + 0.5 + liter + + milk + + + + + First, we need to make the dough: place in a mixing bowl 375g of the flour and make a hole in the middle, where you can place the butter slightly soft, the icing (or normal) sugar, 3 egg yolks, the egg, and 375g flour. Mix all these properly until you get something quite consistant. And leave it in the fridge for at least 1/2 an hour, covered with cling film. + +In the mean time, in order to make some cream, put the milk boiling in a saucepan, and add the cinnamon and the vanilla pod. Midwhile, mix in a bowl the 150 g of the sugar, the rest of the flour (50g), and the 4 egg yolks that are left. Once the milk is boiling, remove the cinnamon and the vanilla pod and add this mixture to the milk. Keep going on mixing continuously until the cream gets quite thick, and once it starts boiling add the almonds, previously grounded, 100 g of sugar which is left, and the currants. Leave this mixture in the fridge for 1/2 an hour. + +Once these two things are done, get a mould ready for baking spreading a bit of butter and then flour so that the cake won't stick to the mould. + +Now, put a thin (less than 5mm) layer of the dough covering the bottom and side parts of the mould, and fill it in with the cream, and cover on top with the rest of the dough in the same way. + +Paint the cake's top part with a bit of whisked egg, and put it in the oven at 190C for around 30 mins. Et voilá! you have a delicious sweet cake. + + + \ No newline at end of file diff --git a/lib/junit-4.10.jar b/lib/junit-4.10.jar new file mode 100644 index 0000000..bf5c0b9 Binary files /dev/null and b/lib/junit-4.10.jar differ diff --git a/lib/xstream-1.4.2.jar b/lib/xstream-1.4.2.jar new file mode 100644 index 0000000..fa8e2ed Binary files /dev/null and b/lib/xstream-1.4.2.jar differ diff --git a/src/net/woodyfolsom/cs6601/p2/Ingredient.java b/src/net/woodyfolsom/cs6601/p2/Ingredient.java new file mode 100644 index 0000000..d8a1fd2 --- /dev/null +++ b/src/net/woodyfolsom/cs6601/p2/Ingredient.java @@ -0,0 +1,12 @@ +package net.woodyfolsom.cs6601.p2; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +@XStreamAlias("ing") +public class Ingredient { + private String item; + + public String getItem() { + return item; + } +} diff --git a/src/net/woodyfolsom/cs6601/p2/Recipe.java b/src/net/woodyfolsom/cs6601/p2/Recipe.java new file mode 100644 index 0000000..24d6182 --- /dev/null +++ b/src/net/woodyfolsom/cs6601/p2/Recipe.java @@ -0,0 +1,24 @@ +package net.woodyfolsom.cs6601.p2; + +import java.util.List; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +@XStreamAlias("recipe") +public class Recipe { + + private List ingredients; + private RecipeHead head; + + public RecipeHead getHead() { + return head; + } + + public Ingredient getIngredient(int index) { + return ingredients.get(index); + } + + public int getIngredientsSize() { + return ingredients.size(); + } +} \ No newline at end of file diff --git a/src/net/woodyfolsom/cs6601/p2/RecipeBook.java b/src/net/woodyfolsom/cs6601/p2/RecipeBook.java new file mode 100644 index 0000000..7f557ac --- /dev/null +++ b/src/net/woodyfolsom/cs6601/p2/RecipeBook.java @@ -0,0 +1,21 @@ +package net.woodyfolsom.cs6601.p2; + +import java.util.List; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamImplicit; + +@XStreamAlias("recipeml") +public class RecipeBook { + + @XStreamImplicit(itemFieldName="recipe") + private List recipes; + + public Recipe getRecipe(int index) { + return recipes.get(index); + } + + public int getSize() { + return recipes.size(); + } +} diff --git a/src/net/woodyfolsom/cs6601/p2/RecipeBookReader.java b/src/net/woodyfolsom/cs6601/p2/RecipeBookReader.java new file mode 100644 index 0000000..28769f3 --- /dev/null +++ b/src/net/woodyfolsom/cs6601/p2/RecipeBookReader.java @@ -0,0 +1,13 @@ +package net.woodyfolsom.cs6601.p2; + +import java.io.File; + +import com.thoughtworks.xstream.XStream; + +public class RecipeBookReader { + private static XStream xstream = XStreamFactory.getInstance(); + + public static RecipeBook readRecipeBook(File recipeBookFile) { + return (RecipeBook) xstream.fromXML(recipeBookFile); + } +} diff --git a/src/net/woodyfolsom/cs6601/p2/RecipeBookStub.java b/src/net/woodyfolsom/cs6601/p2/RecipeBookStub.java new file mode 100644 index 0000000..62094bf --- /dev/null +++ b/src/net/woodyfolsom/cs6601/p2/RecipeBookStub.java @@ -0,0 +1,19 @@ +package net.woodyfolsom.cs6601.p2; + +import java.io.File; + +public class RecipeBookStub { + + /** + * @param args + */ + public static void main(String[] args) { + RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/PastelVasco.xml")); + + System.out.println("Read " + recipeBook.getSize() + " recipes."); + for (int i = 0 ; i < recipeBook.getSize(); i++) { + System.out.println("Read recipe: " + recipeBook.getRecipe(i).getHead().getTitle()); + } + } + +} diff --git a/src/net/woodyfolsom/cs6601/p2/RecipeHead.java b/src/net/woodyfolsom/cs6601/p2/RecipeHead.java new file mode 100644 index 0000000..7e78412 --- /dev/null +++ b/src/net/woodyfolsom/cs6601/p2/RecipeHead.java @@ -0,0 +1,26 @@ +package net.woodyfolsom.cs6601.p2; + +import java.util.List; + +import com.thoughtworks.xstream.annotations.XStreamAlias; + +@XStreamAlias("head") +public class RecipeHead { + + private String title; + private String source; + + private List categories; + + public String getSource() { + return source; + } + + public String getTitle() { + return title; + } + + public boolean isCategoryMatch(String catName) { + return categories.contains(catName); + } +} diff --git a/src/net/woodyfolsom/cs6601/p2/XStreamFactory.java b/src/net/woodyfolsom/cs6601/p2/XStreamFactory.java new file mode 100644 index 0000000..ba58bf5 --- /dev/null +++ b/src/net/woodyfolsom/cs6601/p2/XStreamFactory.java @@ -0,0 +1,37 @@ +package net.woodyfolsom.cs6601.p2; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.collections.CollectionConverter; +import com.thoughtworks.xstream.io.xml.DomDriver; +import com.thoughtworks.xstream.mapper.ClassAliasingMapper; + +public class XStreamFactory { + + public static XStream getInstance() { + XStream xstream = new XStream(new DomDriver()); + + xstream.processAnnotations(RecipeBook.class); + + + xstream.processAnnotations(Recipe.class); + xstream.omitField(Recipe.class, "directions"); + + xstream.processAnnotations(RecipeHead.class); + + ClassAliasingMapper mapper = new ClassAliasingMapper(xstream.getMapper()); + mapper.addClassAlias("cat", String.class); + xstream.registerLocalConverter( + RecipeHead.class, + "categories", + new CollectionConverter(mapper) + ); + + xstream.omitField(RecipeHead.class, "yield"); + xstream.omitField(RecipeHead.class, "preptime"); + + xstream.omitField(Ingredient.class, "amt"); + xstream.omitField(Ingredient.class, "prep"); + + return xstream; + } +} diff --git a/test/net/woodyfolsom/cs6601/p2/RecipeBookReaderTest.java b/test/net/woodyfolsom/cs6601/p2/RecipeBookReaderTest.java new file mode 100644 index 0000000..804d463 --- /dev/null +++ b/test/net/woodyfolsom/cs6601/p2/RecipeBookReaderTest.java @@ -0,0 +1,31 @@ +package net.woodyfolsom.cs6601.p2; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.*; + +import java.io.File; + +import net.woodyfolsom.cs6601.p2.Recipe; +import net.woodyfolsom.cs6601.p2.RecipeBook; +import net.woodyfolsom.cs6601.p2.RecipeBookReader; + +import org.junit.Test; + +public class RecipeBookReaderTest { + + @Test + public void testReadRecipeBook() { + RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/PastelVasco.xml")); + assertNotNull(recipeBook); + assertThat(recipeBook.getSize(), is(equalTo(1))); + + Recipe recipe = recipeBook.getRecipe(0); + assertThat(recipe.getHead().getTitle(), is(equalTo("Gateau Basque / Pastel Vasco"))); + assertTrue(recipe.getHead().isCategoryMatch("Desserts")); + assertTrue(recipe.getHead().isCategoryMatch("Sweets")); + assertFalse(recipe.getHead().isCategoryMatch("Meat")); + } +}