eShopper
Class eShopperUnit

java.lang.Object
  extended byeShopper.eShopperUnit

public class eShopperUnit
extends java.lang.Object

This class implements units and unit conversion for the Ingredients.

Author:
Jim Laing

Constructor Summary
eShopperUnit(int aUnitID, eShopperDB db)
          constructor
 
Method Summary
 float convertFromBase(float value)
          Converts a value expressed in the unit type's base unit to a value expressed in this unit's unit
 float convertToBase(float value)
          Converts a value to this unit's base unit
 float express(float value, eShopperUnit origUnit)
          Expresses a value of the same type in this unit
 java.lang.String getAbbrvString()
          Returns the set abbreviation for this unit
 int getID()
          This returns the unit's ID.
 java.lang.String getName()
          The name of this unit
 java.lang.String getType()
          The type of this unit.
 boolean isAuth()
          Determines whether this unit is set as authoritative.
 boolean isLargerThan(eShopperUnit aUnit)
          Compares the relative size of a unit to this unit
 boolean isSameType(eShopperUnit aUnit)
          Compares the type of units to see if they are combinable.
 java.lang.String toString()
          Gets the abbrviation of a string, for use in various combo boxes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

eShopperUnit

public eShopperUnit(int aUnitID,
                    eShopperDB db)
constructor

Parameters:
aUnitID - the database id of the desired unit
db - the database
Method Detail

toString

public java.lang.String toString()
Gets the abbrviation of a string, for use in various combo boxes

Returns:
a string representation of the unit

getID

public int getID()
This returns the unit's ID.

Returns:
The ID of the unit.

convertFromBase

public float convertFromBase(float value)
Converts a value expressed in the unit type's base unit to a value expressed in this unit's unit

Parameters:
value - a value expressed in the unit types base unit
Returns:
the value expressed in the unit's unit

convertToBase

public float convertToBase(float value)
Converts a value to this unit's base unit

Parameters:
value - a value expessed in this unit's unit
Returns:
a value expressed in this unit's base unit

express

public float express(float value,
                     eShopperUnit origUnit)
              throws java.util.zip.DataFormatException
Expresses a value of the same type in this unit

Parameters:
value - a value expressed in the original unit
origUnit - the original unit
Returns:
the value as expressed in this object's unit
Throws:
java.util.zip.DataFormatException - throws exception when the units are not the same type

getAbbrvString

public java.lang.String getAbbrvString()
Returns the set abbreviation for this unit

Returns:
a string representation of this unit's abbreviation

isLargerThan

public boolean isLargerThan(eShopperUnit aUnit)
                     throws java.util.zip.DataFormatException
Compares the relative size of a unit to this unit

Parameters:
aUnit - a unit to compare to
Returns:
true if passed unit is smaller than this unit. False otherwise
Throws:
java.util.zip.DataFormatException - if the units are not the same type

isSameType

public boolean isSameType(eShopperUnit aUnit)
Compares the type of units to see if they are combinable. As of release, there are four types of units: mass, volume, count, and package but this can be arbitrarily changed according to the values found in the database.

Parameters:
aUnit - the unit in question
Returns:
true in aUnit is the same type as this unit

isAuth

public boolean isAuth()
Determines whether this unit is set as authoritative. Authoritative units should be more genereal than units of the same type (e.g. package is more general than bag or can and hence it is the authoritative unit of type package)

Returns:
true if the unit is set as authoritative, false otherwise

getType

public java.lang.String getType()
The type of this unit. As of writing, package, count, mass, and volume are all types of units

Returns:
a string representation of the type of this unit

getName

public java.lang.String getName()
The name of this unit

Returns:
a string representing the full name of this unit