Ingredients in the ingredient view are alphabetically ordered
This commit is contained in:
parent
5915b658e6
commit
abe9750b9f
1 changed files with 43 additions and 1 deletions
|
|
@ -55,8 +55,50 @@ public class FormalIngredient extends RecipeIngredient implements Scalable<Forma
|
||||||
}
|
}
|
||||||
return amount * unit.get().conversionFactor;
|
return amount * unit.get().conversionFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String normalisedUnit(){
|
||||||
|
Optional<Unit> unit = Unit.fromString(unitSuffix);
|
||||||
|
if (unit.isEmpty() || !unit.get().isFormal() || unit.get().conversionFactor <= 0) {
|
||||||
|
return amount + unitSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
Unit currentUnit = unit.get();
|
||||||
|
double baseAmount = amount * currentUnit.conversionFactor;
|
||||||
|
|
||||||
|
if(currentUnit == Unit.GRAMME){
|
||||||
|
if(baseAmount >= Unit.TONNE.conversionFactor){
|
||||||
|
return baseAmount /Unit.TONNE.conversionFactor + Unit.TONNE.suffix;
|
||||||
|
}
|
||||||
|
if(baseAmount >=Unit.KILOGRAMME.conversionFactor) {
|
||||||
|
return baseAmount / Unit.KILOGRAMME.conversionFactor + Unit.KILOGRAMME.suffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentUnit == Unit.MILLILITRE && baseAmount >= Unit.LITRE.conversionFactor) {
|
||||||
|
return baseAmount /Unit.LITRE.conversionFactor + Unit.LITRE.suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(currentUnit == Unit.TABLESPOON){
|
||||||
|
if(amount>=32){
|
||||||
|
return amount/32 + Unit.POUND.suffix;
|
||||||
|
}
|
||||||
|
if(amount>=16){
|
||||||
|
return amount /16 + Unit.CUP.suffix;
|
||||||
|
}
|
||||||
|
if(amount>=2){
|
||||||
|
return amount /2 + Unit.OUNCE.suffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentUnit == Unit.OUNCE && baseAmount >= 16) {
|
||||||
|
return amount / 16 + Unit.POUND.suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount + currentUnit.suffix;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return amount + unitSuffix + " of " + ingredient.name;
|
return normalisedUnit()+ " of " + ingredient.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue