ca.spaz.cron.database
Class NutrientTable

java.lang.Object
  extended by ca.spaz.cron.database.NutrientTable
Direct Known Subclasses:
AminoAcids, Lipids, MacroNutrients, Minerals, Vitamins

public abstract class NutrientTable
extends java.lang.Object

A base class for a group of related nutrient values Provides common support for loading and updating the database. The nutrient table is expected to have field names that match the names and types of the corresponding database table. This greatly simplifies maintaining the database and generating UI forms through reflection.

Author:
davidson

Constructor Summary
NutrientTable()
           
NutrientTable(Food f)
           
 
Method Summary
 void addFood(NutrientTable toAdd, double weight)
          Add the nutrients in the given table to our total
protected abstract  java.lang.String doGetTableName()
          Subclasses must implement this in order to supply their table name.
 double getAmountByTag(java.lang.String tag)
          Get the amount of a nutrient by the tag name
 java.lang.String getTableName()
          Get the name of the table corresponding to this class.
 void setAmountByTag(java.lang.String tag, double val)
          Set the amount of a nutrient by the tag name
 void updateDatabase()
          Update the existing food information
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NutrientTable

public NutrientTable()

NutrientTable

public NutrientTable(Food f)
Method Detail

getTableName

public java.lang.String getTableName()
Get the name of the table corresponding to this class. By default it uses the class name. Override this method if it is different.

Returns:
the name of the database table for this object

doGetTableName

protected abstract java.lang.String doGetTableName()
Subclasses must implement this in order to supply their table name.

Returns:
the table name to perform lookups on.

addFood

public void addFood(NutrientTable toAdd,
                    double weight)
Add the nutrients in the given table to our total

Parameters:
toAdd - the nutrients ratios to add
weight - multiplier for the amount in the added nutrients

getAmountByTag

public double getAmountByTag(java.lang.String tag)
Get the amount of a nutrient by the tag name

Parameters:
tag - the tag name of the nutrient
Returns:
the amount of the nutrient, or 0 if none found

setAmountByTag

public void setAmountByTag(java.lang.String tag,
                           double val)
Set the amount of a nutrient by the tag name

Parameters:
tag - the tag name of the nutrient
val - the amount of the nutrient, or 0 if none found

updateDatabase

public void updateDatabase()
Update the existing food information



Copyright © 2005 Spaz. All Rights Reserved.