Exemplo n.º 1
0
 /**
  * Check whether this world has proper food rations attached to it.
  *
  * @return | result == | for each food in Food | ( if (this.hasAsFood(food)) | then
  *     canHaveAsFood(food) | && (food.getWorld() == this) )
  */
 @Raw
 public boolean hasProperFoodRations() {
   for (Food food : this.foodRations) {
     if (!canHaveAsFood(food) || food.getWorld() != this) return false;
   }
   return true;
 }
Exemplo n.º 2
0
 /**
  * Add the given food to the set of food rations attached to this world.
  *
  * @param food The food to be added.
  * @post | new.hasAsFood(food)
  * @post | (new food).getWorld() == this
  * @throws IllegalArgumentException("You can't add this food.") | !canHaveAsFood(food)
  * @throws IllegalArgumentException("You can't add this food.") | ( (food != null) | &&
  *     (food.getWorld() != null) )
  */
 public void addAsFood(Food food) throws IllegalArgumentException {
   if (!canHaveAsFood(food)) throw new IllegalArgumentException("You can't add this food.");
   if (food.getWorld() != null) throw new IllegalArgumentException("You can't add this food.");
   this.foodRations.add(food);
   food.setWorld(this);
 }