|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.spaz.cron.datasource.AbstractFoodDataSource
ca.spaz.cron.datasource.AbstractMutableFoodDatasource
public abstract class AbstractMutableFoodDatasource
A partial implementation of a mutable food source. Provides a certain degree of input validation and notification support.
| Constructor Summary | |
|---|---|
protected |
AbstractMutableFoodDatasource(java.lang.String name)
|
| 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 serving)
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. |
protected abstract Food |
doAddFood(Food food)
Add a Food to this datasource. |
protected abstract void |
doAddFoodGroup(FoodGroup foodGroup)
Add a new FoodGroup to the data source. |
protected abstract boolean |
doAddMeasure(Food food,
Measure measure)
Each food in the Datasource has available a list of Measures that
describe portions or servings. |
protected abstract boolean |
doChangeMeasure(Food food,
java.util.List measures)
|
protected abstract boolean |
doChangeServingAmount(Serving serving)
Changes the amount of a food consumed to the amount in the serving provided. |
protected abstract Food |
doConsumeFood(Serving serving)
This method consumes the food in a serving. |
protected abstract Food |
doCreateNewFood()
Create a new Food object associated with this datasource. |
protected abstract int |
doGetTimesConsumed(Food food)
Retrieve the total number of times that this food has been consumed. |
protected abstract int |
doGetTimesConsumed(Food food,
java.util.Date startDate,
java.util.Date endDate)
Retrieve the number of times the specified Food was consumed
between the provided dates. |
protected abstract boolean |
doRemoveFood(Food food)
Remove a Food from the datasource. |
protected abstract boolean |
doRemoveMeasure(Food food,
Measure measure)
Remove a particular form of Measure from the list of those available for
a particular Food. |
protected abstract boolean |
doSaveFood(Food food)
Alter the information of some Food object in the backing representation of the datasource. |
protected abstract boolean |
doUnConsumeFood(Serving serving)
Remove the Food in a particular serving from the user's consumed
list. |
protected abstract Food |
findFoodBySourceUID(java.lang.String sourceUID)
Find a local food by its sourceUID field value. |
protected boolean |
getNotify()
|
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. |
protected void |
notifyObservers(FoodDataEvent type)
|
protected void |
notifyObservers(FoodDataEvent type,
java.lang.Object message)
|
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. |
protected void |
setNotify(boolean notify)
|
| Methods inherited from class ca.spaz.cron.datasource.AbstractFoodDataSource |
|---|
diffSource, doFindAllFoods, doFindFoods, doFindFoods, doGetMeasuresFor, doGetNutrientsFor, findAllFoods, findFoods, findFoods, getLastError, getMeasuresFor, getName, getNutrientsFor, notNull, registerError, sameSource, 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.ILocalFoodDatasource |
|---|
getConsumedOn |
| Methods inherited from interface ca.spaz.cron.datasource.IFoodDatasource |
|---|
close, containsFood, findAllFoods, findFoods, findFoods, getFoodGroups, getLastError, getMeasuresFor, getName, getNutrientsFor, getSources, initialize, isAvailable, isListable, isSearchable |
| Constructor Detail |
|---|
protected AbstractMutableFoodDatasource(java.lang.String name)
| Method Detail |
|---|
protected final void setNotify(boolean notify)
protected final boolean getNotify()
public final Food addFood(Food food)
ILocalFoodDatasourceFood 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.
addFood in interface ILocalFoodDatasourcefood - A Food object that comes from another datasource.
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.protected abstract Food findFoodBySourceUID(java.lang.String sourceUID)
sourceUID - The key to search on
Food found, or null if no food matched.public final Food createNewFood()
ILocalFoodDatasourceFood object associated with this datasource.
createNewFood in interface ILocalFoodDatasourceFood instance.protected abstract Food doCreateNewFood()
Food object associated with this datasource.
Food instance.public final void addFoodDatasourceListener(IFoodDatasourceListener listener)
ILocalFoodDatasourceIFoodDatasourceListener to this implementation. The listener
will be notified on any successful change to the underlying datasource.
addFoodDatasourceListener in interface ILocalFoodDatasourcelistener - the new IFoodDatasourceListener.public final void addFoodGroup(FoodGroup foodGroup)
ILocalFoodDatasource
addFoodGroup in interface ILocalFoodDatasourcefoodGroup - the new food group to add to the data source.protected abstract void doAddFoodGroup(FoodGroup foodGroup)
foodGroup - the new food group to add to the data source.
public final boolean addMeasure(Food food,
Measure measure)
ILocalFoodDatasourceMeasures that
describe portions or servings. This method will add a valid Measure
to a Food object stored in this datasource.
addMeasure in interface ILocalFoodDatasourcefood - The Food object to which the new measure applies.measure - The new Measure.
true if successful, false if some error occurred.public final boolean changeServingAmount(Serving serving)
ILocalFoodDatasourceFood 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.
changeServingAmount in interface ILocalFoodDatasourceserving - a Serving object whose Food's serving
quantity on the proper date will be altered.
true if the serving was altered, false if some
error occurred.public final boolean saveFood(Food food)
ILocalFoodDatasourceFood 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.
saveFood in interface ILocalFoodDatasourcefood - a Food object to be changed.
true if successful, false if some error occurred.
public final boolean changeMeasure(Food food,
java.util.List measures)
changeMeasure in interface ILocalFoodDatasourcetrue if successful, false if some error occurred.public final Food addServing(Serving serving)
ILocalFoodDatasourceFood 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.
addServing in interface ILocalFoodDatasourceserving - a Serving to add to the user's consumed list.
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.protected abstract Food doAddFood(Food food)
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.
food - A Food object that comes from another datasource.
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.
protected abstract boolean doAddMeasure(Food food,
Measure measure)
Measures that
describe portions or servings. This method will add a valid Measure
to a Food object stored in this datasource.
food - The Food object to which the new measure applies.measure - The new Measure.
true if successful, false if some error occurred.protected abstract boolean doChangeServingAmount(Serving serving)
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.
serving - a Serving object whose Food's serving
quantity on the proper date will be altered.
true if the serving was altered, false if some
error occurred.protected abstract boolean doSaveFood(Food food)
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.
food - a Food object to be changed.
true if successful, false if some error occurred.
protected abstract boolean doChangeMeasure(Food food,
java.util.List measures)
food - measures -
true if successful, false if some error occurred.protected abstract Food doConsumeFood(Serving serving)
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.
serving - a Serving to add to the user's consumed list.
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.protected abstract int doGetTimesConsumed(Food food)
food - the Food to check.
-1 on error.
protected abstract int doGetTimesConsumed(Food food,
java.util.Date startDate,
java.util.Date endDate)
Food was consumed
between the provided dates.
food - the Food to check.startDate - the starting date.endDate - the ending date.
-1
on error.protected abstract boolean doRemoveFood(Food food)
Food from the datasource.
food - the Food to remove.
true if successful, false if some error occurred.
protected abstract boolean doRemoveMeasure(Food food,
Measure measure)
Measure from the list of those available for
a particular Food.
food - measure -
true if successful, false if some error occurred.protected abstract boolean doUnConsumeFood(Serving serving)
Food in a particular serving from the user's consumed
list. Operates regardless of quantity.
serving - the serving to un-consume.
true if the action succeeded, false if there
was some error.public final int getTimesConsumed(Food food)
ILocalFoodDatasource
getTimesConsumed in interface ILocalFoodDatasourcefood - the Food to check.
-1 on error.
public final int getTimesConsumed(Food food,
java.util.Date startDate,
java.util.Date endDate)
ILocalFoodDatasourceFood was consumed
between the provided dates.
getTimesConsumed in interface ILocalFoodDatasourcefood - the Food to check.startDate - the starting date.endDate - the ending date.
-1
on error.protected final void notifyObservers(FoodDataEvent type)
protected final void notifyObservers(FoodDataEvent type,
java.lang.Object message)
public final boolean removeFood(Food food)
ILocalFoodDatasourceFood from the datasource.
removeFood in interface ILocalFoodDatasourcefood - the Food to remove.
true if successful, false if some error occurred.public final void removeFoodDatasourceListener(IFoodDatasourceListener listener)
ILocalFoodDatasourceIFoodDatasourceListener from the list of observers of this class.
removeFoodDatasourceListener in interface ILocalFoodDatasourcelistener - the IFoodDatasourceListener.
public final boolean removeMeasure(Food food,
Measure measure)
ILocalFoodDatasourceMeasure from the list of those available for
a particular Food.
removeMeasure in interface ILocalFoodDatasourcetrue if successful, false if some error occurred.public final boolean removeServing(Serving serving)
ILocalFoodDatasourceFood in a particular serving from the user's consumed
list. Operates regardless of quantity.
removeServing in interface ILocalFoodDatasourceserving - the serving to un-consume.
true if the action succeeded, false if there
was some error.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||