|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ca.spaz.cron.datasource.AbstractFoodDataSource ca.spaz.cron.datasource.www.AbstractWWWDatasource
public abstract class AbstractWWWDatasource
The base class of all WWW food datasources. Provides convenience methods for some general functions, as well as some assertions about capabilities.
Constructor Summary | |
---|---|
protected |
AbstractWWWDatasource(java.lang.String name)
|
Method Summary | |
---|---|
void |
close()
Close this connection. |
protected abstract void |
doClose()
|
protected abstract java.util.List |
doFindAllFoods()
Retrieve a list of all foods in this datasource. |
protected java.util.List |
doFindFoods(java.lang.String[] keys)
Retrieve a List of all foods in this particular Datasource. |
protected 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 |
doGetFoodGroups()
Retrieve a list of food groups for this data source. |
protected java.util.List |
doGetMeasuresFor(Food food)
Return a List of Measure objects for the provided food. |
protected void |
doGetNutrientsFor(Food food,
NutrientTable nutrients)
Fill the provided NutrientTable with the nutrients associated with the
Food . |
protected abstract java.util.List |
doGetSources()
Retrieve a list of Sources available from this data source. |
java.util.List |
getFoodGroups()
Get a list of all food groups in this datasource. |
protected java.util.List |
getFoodGroups(java.net.URL sourceUrl,
java.util.regex.Pattern startGroups,
java.util.regex.Pattern endGroups,
java.util.regex.Pattern groupID,
int keyGroup,
int nameGroup)
Utility method to retrieve food groups from a URL's data, using regular expressions to mark the beginning and end of the list, as well as a regex to get the food group itself. |
java.util.List |
getSources()
Get a list of all sources in this datasource. |
void |
initialize()
Initialize the datasource to a working state. |
boolean |
isListable()
Implementors that can provide listing services should return true here, false otherwise. |
boolean |
isSearchable()
Implementors that can provide search services should return true here, false otherwise. |
protected static java.lang.String |
readURLAsString(java.net.URL source)
|
Methods inherited from class ca.spaz.cron.datasource.AbstractFoodDataSource |
---|
diffSource, 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.IFoodDatasource |
---|
containsFood, isAvailable |
Constructor Detail |
---|
protected AbstractWWWDatasource(java.lang.String name)
name
- The unique ID of this data source.Method Detail |
---|
protected abstract java.util.List doFindAllFoods()
AbstractFoodDataSource
doFindAllFoods
in class AbstractFoodDataSource
Food
objects consisting of every food in the datasource.public final java.util.List getSources()
IFoodDatasource
List
of String
objects naming the sources
for this Datasource.protected abstract java.util.List doGetSources()
List
of sources for this datasource.public final java.util.List getFoodGroups()
IFoodDatasource
List
of FoodGroup
objects naming the food
groups for this Datasource.protected abstract java.util.List doGetFoodGroups()
List
of FoodGroup
implementations
containing all of the food groups in this data source.public boolean isSearchable()
IFoodDatasource
true
if this Datasource supports search, false
otherwise.public boolean isListable()
IFoodDatasource
true
if this Datasource supports listing, false
otherwise.public final void close()
IFoodDatasource
protected abstract void doClose()
protected java.util.List getFoodGroups(java.net.URL sourceUrl, java.util.regex.Pattern startGroups, java.util.regex.Pattern endGroups, java.util.regex.Pattern groupID, int keyGroup, int nameGroup) throws java.io.IOException
sourceUrl
- This is the URL whose data will be read.startGroups
- This pattern should mark the beginning of the list of food groups.endGroups
- This pattern should mark the end of the list of food groups.groupID
- This pattern should mark an individual food group. More specifically,
it must provide at least two groupings, one of which will be the group key for
searching, and the other of which will be the group name for display.keyGroup
- This is the group number in the groupID pattern that marks the search
key for the food group.nameGroup
- This is the group number in the groupID pattern that marks the name
of the food group.
List
of FoodGroup implementations that contains all food groups
available at the URL.
java.io.IOException
- if there is an error reading from the URL.protected static java.lang.String readURLAsString(java.net.URL source)
protected java.util.List doFindFoods(java.lang.String[] keys, java.lang.String foodGroup, java.lang.String source)
AbstractFoodDataSource
List
of all foods in this particular Datasource having
the given food group and source.
doFindFoods
in class AbstractFoodDataSource
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.
Food
objects matching the criteria.protected java.util.List doFindFoods(java.lang.String[] keys)
AbstractFoodDataSource
List
of all foods in this particular Datasource.
doFindFoods
in class AbstractFoodDataSource
keys
- the keys to search on. This searches with an AND relation.
Food
objects matching the criteria.protected java.util.List doGetMeasuresFor(Food food)
AbstractFoodDataSource
List
of Measure
objects for the provided food.
doGetMeasuresFor
in class AbstractFoodDataSource
food
- a Food
object to find the measures for
List
that is guaranteed to contain only Measure
objects.protected void doGetNutrientsFor(Food food, NutrientTable nutrients)
AbstractFoodDataSource
NutrientTable
with the nutrients associated with the
Food
.
doGetNutrientsFor
in class AbstractFoodDataSource
food
- The food item to load fromnutrients
- the NutrientTable
to fill.public void initialize()
IFoodDatasource
isAvailable
must return
true
for this data source. If this source is already available, this
method will do nothing.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |