예제 #1
0
 // populate (could optionally have reflective populate)
 public synchronized void populate(SQLRow row) {
   row.setValue("source", food.getSource().getName());
   row.setValue("food", food.getSourceID());
   if (date != 0) {
     row.setValue("time", new Timestamp(date));
   }
   row.setValue("grams", new Double(grams));
   if (measure != Measure.GRAM) {
     row.setValue("measure", measure.getDescription());
   }
 }
예제 #2
0
 public synchronized XMLNode toXML(boolean export) {
   XMLNode node = toXML();
   if (export && (food.getSource() == Datasources.getUserFoods())) {
     if (food.getFood() instanceof Recipe) {
       node.addChild(((Recipe) food.getFood()).toXML(export));
     } else {
       node.addChild(food.getFood().toXML());
     }
   }
   return node;
 }
예제 #3
0
 public boolean equals(FoodProxy fp) {
   if (source != fp.getSource()) {
     return false;
   }
   if (!sourceID.equals(fp.getSourceID())) {
     return false;
   }
   if (!description.equals(fp.getDescription())) {
     return false;
   }
   return true;
 }
예제 #4
0
 private FoodProxy addToUserFoodsIfMissing(String source, Food f) {
   FoodDataSource allegedSource = Datasources.getSource(source);
   if (allegedSource != null) {
     FoodProxy f2 = allegedSource.getFoodProxy(f.getSourceUID());
     if (f2 != null) {
       if (f2.getFood().equals(f)) {
         return f2;
       }
     }
   }
   // TODO: scan all foods for identical matches first!
   Datasources.getUserFoods().addFood(f);
   return f.getProxy();
 }
예제 #5
0
 public void setFood(FoodProxy food) {
   this.food = food;
   assert food != null;
   if (food != null) {
     food.addReference();
   }
 }
예제 #6
0
 public synchronized XMLNode toXML() {
   XMLNode node = new XMLNode("serving");
   node.addAttribute("source", food.getSource().getName());
   node.addAttribute("food", food.getSourceID());
   if (date != 0) {
     node.addAttribute("date", date);
   }
   node.addAttribute("grams", grams);
   if (measure != Measure.GRAM) {
     node.addAttribute("measure", measure.getDescription());
   }
   if (meal != -1) {
     node.addAttribute("meal", meal);
   }
   return node;
 }
예제 #7
0
 public Food getFood() {
   if (food == null) {
     return null;
   }
   return food.getFood();
 }