ca.spaz.cron.datasource
Class AbstractFoodDataSource

java.lang.Object
  extended by ca.spaz.cron.datasource.AbstractFoodDataSource
All Implemented Interfaces:
IFoodDatasource
Direct Known Subclasses:
AbstractMutableFoodDatasource, AbstractWWWDatasource

public abstract class AbstractFoodDataSource
extends java.lang.Object
implements IFoodDatasource

This is a partial implementation of the IFoodDatasource interface, providing checking for proper sources for Food parameters and basic naming. Protected abstract implementation methods are provided for all public methods that this class handles.

Author:
Chris Rose

Constructor Summary
protected AbstractFoodDataSource(java.lang.String name)
          Construct a new instance of this class, with the name supplied.
 
Method Summary
protected  void diffSource(Food food)
          Gatekeeper method to ensure that the Food object is from a different Datasource.
protected abstract  java.util.List doFindAllFoods()
          Retrieve a list of all foods in this datasource.
protected abstract  java.util.List doFindFoods(java.lang.String[] keys)
          Retrieve a List of all foods in this particular Datasource.
protected abstract  java.util.List doFindFoods(java.lang.String[] keys, java.lang.String foodGroup, java.lang.String source)
          Retrieve a List of all foods in this particular Datasource having the given food group and source.
protected abstract  java.util.List doGetMeasuresFor(Food food)
          Return a List of Measure objects for the provided food.
protected abstract  void doGetNutrientsFor(Food food, NutrientTable nutrients)
          Fill the provided NutrientTable with the nutrients associated with the Food.
 java.util.List findAllFoods()
          Retrieve a list of all foods in this datasource.
 java.util.List findFoods(java.lang.String[] keys)
          Retrieve a List of all foods in this particular Datasource.
 java.util.List findFoods(java.lang.String[] keys, java.lang.String foodGroup, java.lang.String source)
          Retrieve a List of all foods in this particular Datasource having the given food group and source.
 FoodDatasourceException getLastError()
          Provides access to the last exception thrown by the underlying representation.
 java.util.List getMeasuresFor(Food food)
          Return a List of Measure objects for the provided food.
 java.lang.String getName()
          Retrieve the name of this datasource for use in UI components.
 void getNutrientsFor(Food food, NutrientTable nutrients)
          Fill the provided NutrientTable with the nutrients associated with the Food.
protected  void notNull(java.lang.Object testedObject)
          Gatekeeper method to ensure that an object is not null.
protected  void registerError(java.lang.Throwable t)
          Set the last error message to the supplied Throwable.
protected  void sameSource(Food food)
          Gatekeeper method to ensure that the Food object is from this Datasource.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ca.spaz.cron.datasource.IFoodDatasource
close, containsFood, getFoodGroups, getSources, initialize, isAvailable, isListable, isSearchable
 

Constructor Detail

AbstractFoodDataSource

protected AbstractFoodDataSource(java.lang.String name)
Construct a new instance of this class, with the name supplied.

Parameters:
name - the name of this datasource.
Method Detail

diffSource

protected void diffSource(Food food)
Gatekeeper method to ensure that the Food object is from a different Datasource.

Parameters:
food - a food object to test.
Throws:
java.lang.IllegalArgumentException - if the food object is from this datasource.

notNull

protected void notNull(java.lang.Object testedObject)
Gatekeeper method to ensure that an object is not null.

Parameters:
testedObject -

doFindAllFoods

protected abstract java.util.List doFindAllFoods()
Retrieve a list of all foods in this datasource.

Returns:
a List of Food objects consisting of every food in the datasource.
Throws:
UnsupportedOperationException - if the datasource does not support listing. (if isListable() is false)

doFindFoods

protected abstract java.util.List doFindFoods(java.lang.String[] keys)
Retrieve a List of all foods in this particular Datasource.

Parameters:
keys - the keys to search on. This searches with an AND relation.
Returns:
a List of Food objects matching the criteria.
Throws:
UnsupportedOperationException - if the datasource does not support searching. (if isSearchable() is false)

doFindFoods

protected abstract java.util.List doFindFoods(java.lang.String[] keys,
                                              java.lang.String foodGroup,
                                              java.lang.String source)
Retrieve a List of all foods in this particular Datasource having the given food group and source.

Parameters:
keys - the keys to search on. This searches with an AND relation.
foodGroup - the food group to search for. null to ignore.
source - the source of this food item. null to ignore.
Returns:
a List of Food objects matching the criteria.
Throws:
UnsupportedOperationException - if the datasource does not support searching. (if isSearchable() is false)

doGetMeasuresFor

protected abstract java.util.List doGetMeasuresFor(Food food)
Return a List of Measure objects for the provided food.

Parameters:
food - a Food object to find the measures for
Returns:
a List that is guaranteed to contain only Measure objects.

doGetNutrientsFor

protected abstract void doGetNutrientsFor(Food food,
                                          NutrientTable nutrients)
Fill the provided NutrientTable with the nutrients associated with the Food.

Parameters:
food - The food item to load from
nutrients - the NutrientTable to fill.

findAllFoods

public final java.util.List findAllFoods()
Description copied from interface: IFoodDatasource
Retrieve a list of all foods in this datasource.

Specified by:
findAllFoods in interface IFoodDatasource
Returns:
a List of Food objects consisting of every food in the datasource.

findFoods

public final java.util.List findFoods(java.lang.String[] keys)
Description copied from interface: IFoodDatasource
Retrieve a List of all foods in this particular Datasource.

Specified by:
findFoods in interface IFoodDatasource
Parameters:
keys - the keys to search on. This searches with an AND relation.
Returns:
a List of Food objects matching the criteria.

findFoods

public final java.util.List findFoods(java.lang.String[] keys,
                                      java.lang.String foodGroup,
                                      java.lang.String source)
Description copied from interface: IFoodDatasource
Retrieve a List of all foods in this particular Datasource having the given food group and source.

Specified by:
findFoods in interface IFoodDatasource
Parameters:
keys - the keys to search on. This searches with an AND relation.
foodGroup - the food group to search for. null to ignore.
source - the source of this food item. null to ignore.
Returns:
a List of Food objects matching the criteria.

getMeasuresFor

public final java.util.List getMeasuresFor(Food food)
Description copied from interface: IFoodDatasource
Return a List of Measure objects for the provided food.

Specified by:
getMeasuresFor in interface IFoodDatasource
Parameters:
food - a Food object to find the measures for
Returns:
a List that is guaranteed to contain only Measure objects.

getName

public java.lang.String getName()
Description copied from interface: IFoodDatasource
Retrieve the name of this datasource for use in UI components.

Specified by:
getName in interface IFoodDatasource
Returns:
this Datasource's name.

getNutrientsFor

public final void getNutrientsFor(Food food,
                                  NutrientTable nutrients)
Description copied from interface: IFoodDatasource
Fill the provided NutrientTable with the nutrients associated with the Food.

Specified by:
getNutrientsFor in interface IFoodDatasource
Parameters:
food - The food item to load from
nutrients - the NutrientTable to fill.

sameSource

protected void sameSource(Food food)
Gatekeeper method to ensure that the Food object is from this Datasource.

Parameters:
food - a food object to test.
Throws:
java.lang.IllegalArgumentException - if the food object is from another datasource.

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

getLastError

public FoodDatasourceException getLastError()
Description copied from interface: IFoodDatasource
Provides access to the last exception thrown by the underlying representation.

Specified by:
getLastError in interface IFoodDatasource
Returns:
the last Throwable that an implementation of this interface has thrown.

registerError

protected void registerError(java.lang.Throwable t)
Set the last error message to the supplied Throwable.

Parameters:
t - the exception that just happened.


Copyright © 2005 Spaz. All Rights Reserved.