ca.spaz.cron.datasource
Interface ILocalFoodDatasource

All Superinterfaces:
IFoodDatasource
All Known Implementing Classes:
AbstractMutableFoodDatasource, SQLDatasource

public interface ILocalFoodDatasource
extends IFoodDatasource

This interface defines a datasource whose contents may be changed by interested classes. All of the standard issues apply (especially the Food needing to be associated with this datasource)

Author:
Chris Rose

Method Summary
 Food addFood(Food food)
          Add a Food to this datasource.
 void addFoodDatasourceListener(IFoodDatasourceListener listener)
          Add a new IFoodDatasourceListener to this implementation.
 void addFoodGroup(FoodGroup foodGroup)
          Add a new FoodGroup to the data source.
 boolean addMeasure(Food food, Measure measure)
          Each food in the Datasource has available a list of Measures that describe portions or servings.
 Food addServing(Serving serving)
          This method consumes the food in a serving.
 boolean changeMeasure(Food food, java.util.List measures)
           
 boolean changeServingAmount(Serving newServing)
          Changes the amount of a food consumed to the amount in the serving provided.
 Food createNewFood()
          Create a new Food object associated with this datasource.
 java.util.List getConsumedOn(java.util.Date date)
          Retrieve a list of all Servings consumed on a particular date.
 int getTimesConsumed(Food food)
          Retrieve the total number of times that this food has been consumed.
 int getTimesConsumed(Food food, java.util.Date startDate, java.util.Date endDate)
          Retrieve the number of times the specified Food was consumed between the provided dates.
 boolean removeFood(Food food)
          Remove a Food from the datasource.
 void removeFoodDatasourceListener(IFoodDatasourceListener listener)
          Remove an IFoodDatasourceListener from the list of observers of this class.
 boolean removeMeasure(Food food, Measure measure)
          Remove a particular form of Measure from the list of those available for a particular Food.
 boolean removeServing(Serving serving)
          Remove the Food in a particular serving from the user's consumed list.
 boolean saveFood(Food food)
          Alter the information of some Food object in the backing representation of the datasource.
 
Methods inherited from interface ca.spaz.cron.datasource.IFoodDatasource
close, containsFood, findAllFoods, findFoods, findFoods, getFoodGroups, getLastError, getMeasuresFor, getName, getNutrientsFor, getSources, initialize, isAvailable, isListable, isSearchable
 

Method Detail

addServing

Food addServing(Serving serving)
This method consumes the food in a serving. This an exception to the requirement that a Food object have this as its datasource, since in this case if the Food object has a different datasource, it will either A) be added to this one, and then consumed, or B) if it is already present in this datasource it will simply be added from this datasource.

Parameters:
serving - a Serving to add to the user's consumed list.
Returns:
A new Food object that represents the Food that is associated with this datasource. If the food was already associated with this datasource, the same object will be returned. null will be returned if some error occurred.

addFoodGroup

void addFoodGroup(FoodGroup foodGroup)
Add a new FoodGroup to the data source. The food group may already exist, in which case an implementing method should silently succeed.

Parameters:
foodGroup - the new food group to add to the data source.

changeServingAmount

boolean changeServingAmount(Serving newServing)
Changes the amount of a food consumed to the amount in the serving provided. This will alter the amount of the Food retrieved by calling getFood() on newServing. If the food is not already in the database as being consumed, it will be added. The food must already be in the user datasource, however.

Parameters:
newServing - a Serving object whose Food's serving quantity on the proper date will be altered.
Returns:
true if the serving was altered, false if some error occurred.

removeServing

boolean removeServing(Serving serving)
Remove the Food in a particular serving from the user's consumed list. Operates regardless of quantity.

Parameters:
serving - the serving to un-consume.
Returns:
true if the action succeeded, false if there was some error.

addMeasure

boolean addMeasure(Food food,
                   Measure measure)
Each food in the Datasource has available a list of Measures that describe portions or servings. This method will add a valid Measure to a Food object stored in this datasource.

Parameters:
food - The Food object to which the new measure applies.
measure - The new Measure.
Returns:
true if successful, false if some error occurred.

changeMeasure

boolean changeMeasure(Food food,
                      java.util.List measures)
Parameters:
food -
measures -
Returns:
true if successful, false if some error occurred.

removeMeasure

boolean removeMeasure(Food food,
                      Measure measure)
Remove a particular form of Measure from the list of those available for a particular Food.

Parameters:
food -
measure -
Returns:
true if successful, false if some error occurred.

getTimesConsumed

int getTimesConsumed(Food food)
Retrieve the total number of times that this food has been consumed.

Parameters:
food - the Food to check.
Returns:
the number of times consumed, or -1 on error.

getTimesConsumed

int getTimesConsumed(Food food,
                     java.util.Date startDate,
                     java.util.Date endDate)
Retrieve the number of times the specified Food was consumed between the provided dates.

Parameters:
food - the Food to check.
startDate - the starting date.
endDate - the ending date.
Returns:
the number of times consumed between the two dates, or -1 on error.

getConsumedOn

java.util.List getConsumedOn(java.util.Date date)
Retrieve a list of all Servings consumed on a particular date.

Parameters:
date - the Date to retrieve the foods for.
Returns:
a List consisting only of Serving objects, or null if some error occurred. If no servings were consumed on the specified date, an empty list will be returned.

addFood

Food addFood(Food food)
Add a Food to this datasource. This method is an exception to the local datasource rule -- the Food provided to this method must not be attached to this datasource.

Parameters:
food - A Food object that comes from another datasource.
Returns:
a Food object whose information is the same as the parameter, but that exists only in this datasource, with all nutrient information still represtented. null will be returned if some error occurred.

createNewFood

Food createNewFood()
Create a new Food object associated with this datasource.

Returns:
a new Food instance.

saveFood

boolean saveFood(Food food)
Alter the information of some Food object in the backing representation of the datasource. This method has potential complications. If the Food implementation specific to the datasource has a concept of unique identifiers, a true alteration will occur. However, if the Food object does not have this feature, for example in a flat-file database or something like it, the implementor should check for name similarity, and if that does not match, simply add the new food to the database.

Parameters:
food - a Food object to be changed.
Returns:
true if successful, false if some error occurred.

removeFood

boolean removeFood(Food food)
Remove a Food from the datasource.

Parameters:
food - the Food to remove.
Returns:
true if successful, false if some error occurred.

addFoodDatasourceListener

void addFoodDatasourceListener(IFoodDatasourceListener listener)
Add a new IFoodDatasourceListener to this implementation. The listener will be notified on any successful change to the underlying datasource.

Parameters:
listener - the new IFoodDatasourceListener.

removeFoodDatasourceListener

void removeFoodDatasourceListener(IFoodDatasourceListener listener)
Remove an IFoodDatasourceListener from the list of observers of this class.

Parameters:
listener - the IFoodDatasourceListener.


Copyright © 2005 Spaz. All Rights Reserved.