Package com.xffffff.wellfed.unit
Class UnitConverter
- java.lang.Object
-
- com.xffffff.wellfed.unit.UnitConverter
-
public class UnitConverter extends java.lang.Object
UnitConverter is a class that converts units to other units It is used to convert units in the Ingredients and Recipe ingredients
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.HashMap<java.lang.String,java.lang.Double>
ingredientDensityMap
The ingredient density map is a map of ingredient names to their densities in g/mL(package private) java.util.ArrayList<java.lang.String>
units
The units ArrayList is an ArrayList of all the units that are supported by the app
-
Constructor Summary
Constructors Constructor Description UnitConverter(android.content.Context context)
The UnitConverter constructor initializes the ingredientDensityMap and units ArrayList
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description android.util.Pair<java.lang.Double,java.lang.String>
availableUnits(Ingredient ingredient)
Converts ingredients to mass if possibleUnit
build(java.lang.String unit)
build method builds a unit from a stringjava.lang.Double
convert(double value, Unit from, Unit to)
The convert method converts a quantity from one unit to another unitjava.lang.Double
convert(double value, java.lang.String ingredient, Unit from, Unit to)
The convert method converts a quantity from one unit to another unitandroid.util.Pair<java.lang.Double,java.lang.String>
convertToSmallest(java.lang.String unitString, java.lang.Double value)
Convert the given unit to the smallest unit in the unit systemjava.lang.String
format(double value, java.lang.String ingredient, Unit from, Unit to)
The format method formats a quantity to a specified unitjava.util.ArrayList<java.lang.String>
getUnits()
Gets all of the units being used, out of count/mass/volumejava.util.ArrayList<Unit>
getUnitsLike(Unit unit)
getUnitsLike method gets all the units that are like the specified unitandroid.util.Pair<java.lang.Double,Unit>
scaleUnit(double value, Unit unit)
the scaleUnit method scales a unit to a specified unit
-
-
-
Field Detail
-
ingredientDensityMap
java.util.HashMap<java.lang.String,java.lang.Double> ingredientDensityMap
The ingredient density map is a map of ingredient names to their densities in g/mL
-
units
java.util.ArrayList<java.lang.String> units
The units ArrayList is an ArrayList of all the units that are supported by the app
-
-
Method Detail
-
convert
public java.lang.Double convert(double value, java.lang.String ingredient, Unit from, Unit to)
The convert method converts a quantity from one unit to another unit- Parameters:
value
- the quantity to convertingredient
- the ingredient to convertfrom
- the unit to convert fromto
- the unit to convert to- Returns:
- the converted quantity
-
convert
public java.lang.Double convert(double value, Unit from, Unit to)
The convert method converts a quantity from one unit to another unit- Parameters:
value
- the quantity to convertfrom
- the unit to convert fromto
- the unit to convert to- Returns:
- the converted quantity
-
format
public java.lang.String format(double value, java.lang.String ingredient, Unit from, Unit to)
The format method formats a quantity to a specified unit- Parameters:
value
- the quantity to formatingredient
- the ingredient to formatfrom
- the unit to format fromto
- the unit to format to- Returns:
- the formatted quantity
-
scaleUnit
public android.util.Pair<java.lang.Double,Unit> scaleUnit(double value, Unit unit)
the scaleUnit method scales a unit to a specified unit- Parameters:
value
- the quantity to scaleunit
- the unit to scale- Returns:
- the scaled unit
-
build
public Unit build(java.lang.String unit)
build method builds a unit from a string- Parameters:
unit
- the string to build the unit from- Returns:
- the built unit
-
getUnitsLike
public java.util.ArrayList<Unit> getUnitsLike(Unit unit)
getUnitsLike method gets all the units that are like the specified unit- Parameters:
unit
- the unit to get units like- Returns:
- the units that are like the specified unit
-
getUnits
public java.util.ArrayList<java.lang.String> getUnits()
Gets all of the units being used, out of count/mass/volume- Returns:
- an arraylist of all units
-
convertToSmallest
public android.util.Pair<java.lang.Double,java.lang.String> convertToSmallest(java.lang.String unitString, java.lang.Double value)
Convert the given unit to the smallest unit in the unit system- Parameters:
unitString
- the unit to convertvalue
- the value of the unit- Returns:
- the converted unit
-
availableUnits
public android.util.Pair<java.lang.Double,java.lang.String> availableUnits(Ingredient ingredient)
Converts ingredients to mass if possible- Parameters:
ingredient
- assumes that ingredient has been converted usingconvertToSmallest(String, Double)
- Returns:
- the converted ingredient
-
-