2022-01-13 23:46:28 +00:00
|
|
|
package com.mousetech.gourmetj;
|
|
|
|
|
|
|
|
import com.mousetech.gourmetj.utils.IngredientDigester;
|
|
|
|
import com.mousetech.gourmetj.utils.IngredientDigester.IngredientAmountFormat;
|
|
|
|
|
|
|
|
public class ShopIngredient implements Comparable<Object> {
|
2022-01-16 13:52:04 +00:00
|
|
|
|
2022-01-13 23:46:28 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param shopCat
|
|
|
|
* @param ingkey
|
|
|
|
*/
|
|
|
|
public ShopIngredient( String shopCat, String item,
|
|
|
|
String ingkey) {
|
|
|
|
this.shopCat = shopCat;
|
|
|
|
this.ingkey = ingkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param amount
|
|
|
|
* @param unit
|
|
|
|
* @param item
|
|
|
|
* @param ingkey
|
|
|
|
* @param shopCat
|
|
|
|
*/
|
2022-01-15 23:06:45 +00:00
|
|
|
public ShopIngredient( Double amount, String unit,
|
2022-01-13 23:46:28 +00:00
|
|
|
String item, String ingkey,
|
2022-01-16 13:52:04 +00:00
|
|
|
String shopCat, boolean inPantry) {
|
2022-01-13 23:46:28 +00:00
|
|
|
this.amount = amount;
|
|
|
|
this.unit = unit;
|
|
|
|
this.item = item;
|
|
|
|
this.ingkey = ingkey;
|
|
|
|
this.shopCat = shopCat;
|
2022-01-16 13:52:04 +00:00
|
|
|
this.inPantry = inPantry;
|
2022-01-13 23:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private String shopCat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the shopCat
|
|
|
|
*/
|
|
|
|
public String getShopCat() {
|
|
|
|
return shopCat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param shopCat the shopCat to set
|
|
|
|
*/
|
|
|
|
public void setShopCat(String shopCat) {
|
|
|
|
this.shopCat = shopCat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the ingkey
|
|
|
|
*/
|
|
|
|
public String getIngkey() {
|
|
|
|
return ingkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ingkey the ingkey to set
|
|
|
|
*/
|
|
|
|
public void setIngkey(String ingkey) {
|
|
|
|
this.ingkey = ingkey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the amount
|
|
|
|
*/
|
2022-01-15 23:06:45 +00:00
|
|
|
public Double getAmount() {
|
2022-01-13 23:46:28 +00:00
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param amount the amount to set
|
|
|
|
*/
|
2022-01-15 23:06:45 +00:00
|
|
|
public void setAmount(Double amount) {
|
2022-01-13 23:46:28 +00:00
|
|
|
this.amount = amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the displayAmount
|
|
|
|
*/
|
|
|
|
public String getDisplayAmount() {
|
2022-01-15 23:06:45 +00:00
|
|
|
Double amt = this.getAmount();
|
|
|
|
if ( amt == null) {
|
|
|
|
return "";
|
|
|
|
}
|
2022-01-13 23:46:28 +00:00
|
|
|
return IngredientDigester.displayAmount(
|
2022-01-15 23:06:45 +00:00
|
|
|
IngredientAmountFormat.IA_TEXT, amt,
|
2022-01-13 23:46:28 +00:00
|
|
|
null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the unit
|
|
|
|
*/
|
|
|
|
public String getUnit() {
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param unit the unit to set
|
|
|
|
*/
|
|
|
|
public void setUnit(String unit) {
|
|
|
|
this.unit = unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String item;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the item
|
|
|
|
*/
|
|
|
|
public String getItem() {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String ingkey;
|
2022-01-15 23:06:45 +00:00
|
|
|
private Double amount;
|
2022-01-13 23:46:28 +00:00
|
|
|
private String displayAmount;
|
|
|
|
private String unit;
|
2022-01-16 13:52:04 +00:00
|
|
|
private boolean inPantry;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the inPantry
|
|
|
|
*/
|
|
|
|
public boolean isInPantry() {
|
|
|
|
return inPantry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param inPantry the inPantry to set
|
|
|
|
*/
|
|
|
|
public void setInPantry(boolean inPantry) {
|
|
|
|
this.inPantry = inPantry;
|
|
|
|
}
|
2022-01-13 23:46:28 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(Object o) {
|
|
|
|
if ((o == null) || !(o instanceof ShopIngredient)) {
|
|
|
|
throw new RuntimeException(
|
|
|
|
"Invalid shipIngredient comparison");
|
|
|
|
}
|
|
|
|
ShopIngredient o1 = (ShopIngredient) o;
|
|
|
|
int i = relate(this.getItem(), o1.getItem());
|
|
|
|
if (i != 0) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
i = relate(this.getShopCat(), o1.getShopCat());
|
|
|
|
if (i != 0) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
// TODO: normalize case, singular/plural/abbreviations
|
|
|
|
i = relate(this.getUnit(), o1.getUnit());
|
|
|
|
if (i != 0) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return i; // ZERO
|
|
|
|
}
|
|
|
|
|
|
|
|
private int relate(String item2, String item3) {
|
|
|
|
if ((item2 == null) && (item3 == null)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (item2 == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (item3 == null) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return item2.compareTo(item3);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return this.getAmount() + " " + this.getUnit() + " "
|
|
|
|
+ this.getItem() + " " + this.getIngkey() + " "
|
|
|
|
+ this.getShopCat();
|
|
|
|
}
|
|
|
|
}
|