1
2
3
4 package ca.spaz.cron.database;
5
6
7 /***
8 * A measure maps a common measure for a food item (ie: a Cup, Teaspoon,
9 * Serving, etc...) The Measure contains the description of the measure and the
10 * number of grams of the food there are in the given measure.
11 *
12 * @author davidson
13 */
14 public class Measure {
15
16 public final static Measure GRAM = new Measure(1.0, "g", 1.0);
17
18 private double grams;
19
20 private double amount;
21
22 private String description;
23
24 private int ID = -1;
25 private int FID = -1;
26
27 public Measure() {
28 }
29
30 /***
31 * Contruct a measure manually
32 *
33 * @param amount
34 * the multiplier of the measure (ex: 0.5)
35 * @param description
36 * the measure name (ex: Cups)
37 * @param grams
38 * the number of grams in the multiple of this type (ex: grams in
39 * 1/2 a Cup)
40 */
41 public Measure(double amount, String description, double grams) {
42 this.amount = amount;
43 this.description = description;
44 this.grams = grams;
45 }
46
47 /***
48 * Get the standard amount of this measure. Example: 1.0 Servings, 0.5 Cups,
49 * 2.0 Tablespoons
50 *
51 * @return the multiplier for this measure
52 */
53 public double getAmount() {
54 return amount;
55 }
56
57 /***
58 * Set the standard amount of this measure
59 *
60 * @param amount
61 * a multiplier
62 */
63 public void setAmount(double amount) {
64 this.amount = amount;
65 }
66
67 /***
68 * Get the english name of the measure type
69 *
70 * @return the english name of the measure type
71 */
72 public String getDescription() {
73 return description;
74 }
75
76 /***
77 * Set the english name of this measure type
78 */
79 public void setDescription(String description) {
80 this.description = description;
81 }
82
83 /***
84 * Get the number of grams in this measure
85 *
86 * @return the number of grams in the measure
87 */
88 public double getGrams() {
89 return grams;
90 }
91
92 /***
93 * Set the number of grams in this measure
94 */
95 public void setGrams(double grams) {
96 this.grams = grams;
97 }
98
99 public String toString() {
100 if (amount != 1.0) {
101 if (amount == 0.5) {
102 return "1/2 " + description;
103 }
104 if (amount == (int)amount) {
105 return (int)amount + " " + description;
106 }
107 return amount + " " + description;
108 }
109 return description;
110 }
111
112 public int getID() {
113 return ID;
114 }
115
116 public void setID(int id) {
117 ID = id;
118 }
119
120 public int getFoodID() {
121 return FID;
122 }
123
124 public void setFoodID(int fid) {
125 FID = fid;
126 }
127
128 }