// 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()); } }
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; }
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; }
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(); }
public void setFood(FoodProxy food) { this.food = food; assert food != null; if (food != null) { food.addReference(); } }
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; }
public Food getFood() { if (food == null) { return null; } return food.getFood(); }