Initial commit.
This commit is contained in:
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
bin
|
||||
build
|
||||
classes
|
||||
dist
|
||||
docs
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
90
build.xml
Normal file
90
build.xml
Normal file
@@ -0,0 +1,90 @@
|
||||
<project name="CS6601_P2" default="dist" basedir=".">
|
||||
<description>
|
||||
simple example build file
|
||||
</description>
|
||||
|
||||
<!-- set global properties for this build -->
|
||||
<property name="build" location="classes" />
|
||||
<property name="dist" location="dist" />
|
||||
<property name="docs" location="docs" />
|
||||
<property name="lib" location="lib" />
|
||||
<property name="data" location="data" />
|
||||
<property name="project.name" value="CS6601_P2" />
|
||||
<property name="src" location="src" />
|
||||
<property name="test" location="test" />
|
||||
|
||||
<path id="build.classpath">
|
||||
<fileset dir="${lib}">
|
||||
<include name="**/*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="classpath.test">
|
||||
<path refid="build.classpath" />
|
||||
<pathelement location="lib/junit-4.10.jar" />
|
||||
<pathelement location="${build}" />
|
||||
</path>
|
||||
|
||||
<target name="clean" description="clean up">
|
||||
<!-- Delete the ${build} and ${dist} directory trees -->
|
||||
<delete dir="${build}" />
|
||||
<delete dir="${dist}" />
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="copy-resources">
|
||||
<!-- Compile the java code from ${src} into ${build} -->
|
||||
<javac srcdir="${src}" destdir="${build}" classpathref="build.classpath" debug="true" source="1.6" target="1.6"/>
|
||||
</target>
|
||||
|
||||
<target name="compile-test" depends="compile">
|
||||
<javac srcdir="${test}" destdir="${build}" debug="true">
|
||||
<classpath refid="classpath.test"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="copy-resources" depends="init" >
|
||||
<copy todir="${build}/data">
|
||||
<fileset dir="${data}">
|
||||
<include name="**/*" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<!--copy file="DetailedInfo.txt" todir="${dist}" /-->
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="copy-resources, compile"
|
||||
description="generate the distribution">
|
||||
<jar jarfile="${dist}/${project.name}.jar">
|
||||
<fileset dir="${build}" excludes="**/*Test.class" />
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="net.woodyfolsom.cs6601.p2.RecipeBookStub" />
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<!-- Creates Javadoc -->
|
||||
<target name="docs" depends="compile">
|
||||
<javadoc packagenames="src" sourcepath="${src}" destdir="${docs}">
|
||||
<!-- Define which files / directory should get included, we include all -->
|
||||
<fileset dir="${src}">
|
||||
<include name="**" />
|
||||
</fileset>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
<target name="init">
|
||||
<!-- Create the time stamp -->
|
||||
<tstamp />
|
||||
<!-- Create the build directory structure used by compile -->
|
||||
<mkdir dir="${build}" />
|
||||
</target>
|
||||
|
||||
<target name="test" depends="compile-test">
|
||||
<junit haltonfailure="true">
|
||||
<classpath refid="classpath.test" />
|
||||
<formatter type="brief" usefile="false" />
|
||||
<batchtest>
|
||||
<fileset dir="${build}" includes="**/*Test.class" />
|
||||
</batchtest>
|
||||
</junit>
|
||||
</target>
|
||||
</project>
|
||||
123
data/PastelVasco.xml
Normal file
123
data/PastelVasco.xml
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE recipeml PUBLIC "-//FormatData//DTD RecipeML 0.5//EN" "http://www.formatdata.com/recipeml/recipeml.dtd"><recipeml version="0.5" generator="Krecipes v2.0-beta1">
|
||||
<recipe>
|
||||
<head>
|
||||
<title>Gateau Basque / Pastel Vasco</title>
|
||||
<source>
|
||||
<srcitem>Unai Garro</srcitem>
|
||||
</source>
|
||||
<categories>
|
||||
<cat>Desserts</cat>
|
||||
<cat>Sweets</cat>
|
||||
</categories>
|
||||
<yield>4</yield>
|
||||
<preptime type="Total">
|
||||
<time>
|
||||
<qty>0</qty>
|
||||
<timeunit>minutes</timeunit>
|
||||
</time>
|
||||
</preptime>
|
||||
</head>
|
||||
<ingredients>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>185</qty>
|
||||
<unit>grams</unit>
|
||||
</amt>
|
||||
<item>butter</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>425</qty>
|
||||
<unit>grams</unit>
|
||||
</amt>
|
||||
<item>flour</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>250</qty>
|
||||
<unit>grams</unit>
|
||||
</amt>
|
||||
<item>sugar</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>7</qty>
|
||||
<unit></unit>
|
||||
</amt>
|
||||
<item>egg yolks</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>1</qty>
|
||||
<unit></unit>
|
||||
</amt>
|
||||
<item>eggs</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>300</qty>
|
||||
<unit>grams</unit>
|
||||
</amt>
|
||||
<item>icing sugar</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>1</qty>
|
||||
<unit>stick</unit>
|
||||
</amt>
|
||||
<item>cinnamon</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>1</qty>
|
||||
<unit></unit>
|
||||
</amt>
|
||||
<item>vanilla pods</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>100</qty>
|
||||
<unit>grams</unit>
|
||||
</amt>
|
||||
<item>almonds</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>100</qty>
|
||||
<unit>grams</unit>
|
||||
</amt>
|
||||
<item>currants</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
<ing>
|
||||
<amt>
|
||||
<qty>0.5</qty>
|
||||
<unit>liter</unit>
|
||||
</amt>
|
||||
<item>milk</item>
|
||||
<prep></prep>
|
||||
</ing>
|
||||
</ingredients>
|
||||
<directions>
|
||||
<step>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.</step>
|
||||
</directions>
|
||||
</recipe>
|
||||
</recipeml>
|
||||
BIN
lib/junit-4.10.jar
Normal file
BIN
lib/junit-4.10.jar
Normal file
Binary file not shown.
BIN
lib/xstream-1.4.2.jar
Normal file
BIN
lib/xstream-1.4.2.jar
Normal file
Binary file not shown.
12
src/net/woodyfolsom/cs6601/p2/Ingredient.java
Normal file
12
src/net/woodyfolsom/cs6601/p2/Ingredient.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
24
src/net/woodyfolsom/cs6601/p2/Recipe.java
Normal file
24
src/net/woodyfolsom/cs6601/p2/Recipe.java
Normal file
@@ -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<Ingredient> ingredients;
|
||||
private RecipeHead head;
|
||||
|
||||
public RecipeHead getHead() {
|
||||
return head;
|
||||
}
|
||||
|
||||
public Ingredient getIngredient(int index) {
|
||||
return ingredients.get(index);
|
||||
}
|
||||
|
||||
public int getIngredientsSize() {
|
||||
return ingredients.size();
|
||||
}
|
||||
}
|
||||
21
src/net/woodyfolsom/cs6601/p2/RecipeBook.java
Normal file
21
src/net/woodyfolsom/cs6601/p2/RecipeBook.java
Normal file
@@ -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<Recipe> recipes;
|
||||
|
||||
public Recipe getRecipe(int index) {
|
||||
return recipes.get(index);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return recipes.size();
|
||||
}
|
||||
}
|
||||
13
src/net/woodyfolsom/cs6601/p2/RecipeBookReader.java
Normal file
13
src/net/woodyfolsom/cs6601/p2/RecipeBookReader.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
19
src/net/woodyfolsom/cs6601/p2/RecipeBookStub.java
Normal file
19
src/net/woodyfolsom/cs6601/p2/RecipeBookStub.java
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
src/net/woodyfolsom/cs6601/p2/RecipeHead.java
Normal file
26
src/net/woodyfolsom/cs6601/p2/RecipeHead.java
Normal file
@@ -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<String> categories;
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public boolean isCategoryMatch(String catName) {
|
||||
return categories.contains(catName);
|
||||
}
|
||||
}
|
||||
37
src/net/woodyfolsom/cs6601/p2/XStreamFactory.java
Normal file
37
src/net/woodyfolsom/cs6601/p2/XStreamFactory.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
31
test/net/woodyfolsom/cs6601/p2/RecipeBookReaderTest.java
Normal file
31
test/net/woodyfolsom/cs6601/p2/RecipeBookReaderTest.java
Normal file
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user