View Javadoc

1   /*
2    *******************************************************************************
3    * Copyright (c) 2005 Chris Rose and AIMedia
4    * All rights reserved. Food and the accompanying materials
5    * are made available under the terms of the Common Public License v1.0
6    * which accompanies this distribution, and is available at
7    * http://www.eclipse.org/legal/cpl-v10.html
8    * 
9    * Contributors:
10   *     Chris Rose
11   *******************************************************************************/
12  package ca.spaz.cron.database;
13  
14  import java.util.List;
15  
16  import ca.spaz.cron.datasource.IFoodDatasource;
17  
18  /***
19   * This interface defines a Food object in CRON-O-Meter. 
20   * @author Chris Rose
21   */
22  public interface Food {
23  
24     /***
25      * Get the FoodGroup associated with this food
26      * 
27      * @return a <code>FoodGroup</code> instance associated with this food.
28      */
29     FoodGroup getFoodGroup();
30  
31     /***
32      * Set the FoodGroup associated with this food.  The <code>Food</code> 
33      * implementation must be associated with a writeable datasource.  If the
34      * <code>FoodGroup</code> is not already in this <code>Food</code>'s datasource,
35      * it will be added.
36      * 
37      * @param foodGroup A <code>FoodGroup</code> instance.
38      */
39     void setFoodGroup(FoodGroup foodGroup);
40  
41     /***
42      * Get a textual description of the food.
43      * 
44      * @return this Food's description.
45      */
46     String getDescription();
47  
48     /***
49      * Update this Food's description.  The <code>Food</code> 
50      * implementation must be associated with a writeable datasource.
51      * 
52      * @param text The new description.
53      */
54     void setDescription(String text);
55  
56     /***
57      * Retrieve a List of <code>Measure</code>s for this Food.
58      * 
59      * @return all <code>Measure</code>s associated with this Food.
60      */
61     List getMeasures();
62  
63     /***
64      * Replace the list of <code>Measure</code>s for this food.  The <code>Food</code> 
65      * implementation must be associated with a writeable datasource.
66      * 
67      * @param measures A list of <code>Measure</code> objects that will completely
68      * replace the ones currently in existence for this <code>Food</code>.
69      */
70     void setMeasures(List measures);
71  
72     /***
73      * A convenience method to retrieve the number of calories this Food provides.
74      * 
75      * @deprecated This method should apply only to Servings.
76      * @return The number of calories provided in one gram of this food.
77      */
78     double getCalories();
79  
80     /***
81      * Retrieve the MacroNutrients list for this Food.
82      * 
83      * @return the MacroNutrients.
84      */
85     MacroNutrients getMacroNutrients();
86  
87     /***
88      * Retrieve the Minerals list for this Food.
89      * 
90      * @return the Minerals.
91      */
92     Minerals getMinerals();
93  
94     /***
95      * Retrieve the Vitamins list for this Food.
96      * 
97      * @return the Vitamins.
98      */
99     Vitamins getVitamins();
100 
101    /***
102     * Retrieve the Amino Acids list for this Food.
103     * 
104     * @return the Amino Acids.
105     */
106    AminoAcids getAminoAcids();
107    
108    /***
109     * Retrieve the Lipids list for this Food.
110     * 
111     * @return the Lipids.
112     */
113    Lipids getLipids();
114 
115    /***
116     * Get the amount of a nutrient provided by this Food.
117     * 
118     * @param ni the <code>NutrientInfo</code> to look up.
119     * @return the amount of the requested nutrient per unit.
120     */
121    double getNutrientAmount(NutrientInfo ni);
122 
123    /***
124     * Set the amount of a nutrient provided by this Food.  The <code>Food</code> 
125     * implementation must be associated with a writeable datasource.
126     * 
127     * @param ni the Nutrient to modify.
128     * @param val the amount of the Nutrient per unit.
129     */
130    void setNutrientAmount(NutrientInfo ni, double val);
131 
132    /***
133     * Get the number of times this food was consumed.
134     * 
135     * @todo Determine if this Food can be associated with other instances of the same
136     * between datasources.
137     * @return the number of times this food was consumed.
138     */
139    int getNumTimesConsumed();
140 
141    /***
142     * Get the identifying 'source' of this food.  This is distinct from the physical
143     * datasource, and is instead intended to allow multiple sources of food to coexist
144     * in a single food DB.
145     * 
146     * @return the source of this Food.
147     */
148    String getSource();
149 
150    /***
151     * Set the identifying 'source' of this Food.  The <code>Food</code> 
152     * implementation must be associated with a writeable datasource.
153     * 
154     * @param source
155     */
156    void setSource(String source);
157    
158    /***
159     * @return Returns the dataSource.
160     */
161    IFoodDatasource getDataSource();
162    
163    /***
164     * Retrieve a key for this food uniquely identifying both its datasource
165     * and its own unique ID in the DS.  The general contract of this method is that
166     * if f1.getSourceUID().equals(f2.getSourceUID()) then f1 and f2 both come from
167     * the same DS, and refer to the same item in that DS.
168     * @return A UID for this food.
169     */
170    String getSourceUID();
171 
172    /***
173     * Call this method to set the food as modified.  This will clear any stored sourceUID in the 
174     * food, and cause it to report its sourceUID() as if it were newly created in the datasource.
175     * This method is NOT reversible.
176     */
177    void setModified();
178 
179    /***
180     * Directly set the sourceUID of a food to that of another one.
181     * @param uid The <code>Food</code> whose sourceUID will be used.
182     */
183    void setSourceUID(String uid);
184 
185 }