62 lines
1.6 KiB
Java
62 lines
1.6 KiB
Java
package net.woodyfolsom.cs6601.p2;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
|
|
|
@XStreamAlias("ing")
|
|
public class Ingredient {
|
|
public enum TYPE { ALCOHOL, BEEF, DAIRY, EGGS, FISH, GENERIC_NUTS, GLUTEN, GRAIN, PORK, POULTRY, POTATO, SHELLFISH, SPICE, SUGAR, TOMATO}
|
|
|
|
private String item;
|
|
|
|
public String getItem() {
|
|
return item;
|
|
}
|
|
|
|
public Set<TYPE> getTypes() {
|
|
Set<TYPE> types = new HashSet<TYPE>();
|
|
for (TYPE type : TYPE.values()) {
|
|
if (isType(type)) {
|
|
types.add(type);
|
|
}
|
|
}
|
|
return types;
|
|
}
|
|
|
|
public boolean isType(TYPE type) {
|
|
switch (type) {
|
|
case BEEF :
|
|
//For our purposes, veal is just expensive beef
|
|
return item.contains("beef") || item.contains("veal") || item.contains("steak");
|
|
case DAIRY :
|
|
return item.contains("margarine") || item.contains("milk");
|
|
case EGGS :
|
|
return item.equals("egg") || item.equals("eggs");
|
|
case GENERIC_NUTS :
|
|
//cashews, peanuts or generic nuts
|
|
return item.contains("cashew") || item.contains("peanut") || item.contains("nuts");
|
|
case GLUTEN :
|
|
return item.contains("flour");
|
|
case PORK :
|
|
return item.contains("pork");
|
|
case POTATO :
|
|
return item.contains("potato");
|
|
case SPICE :
|
|
return item.endsWith("cinnamon") || item.endsWith("nutmeg") || item.endsWith("cloves");
|
|
case SUGAR :
|
|
return item.endsWith("sugar");
|
|
case TOMATO :
|
|
return item.contains("tomato");
|
|
default : //unknown ingredient, e.g. coffee, bananas, honey
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public Object readResolve() {
|
|
item = item.toLowerCase();
|
|
return this;
|
|
}
|
|
}
|