zoo_app/app/src/main/java/com/example/jhalloran/zoo/allocator/AutoAllocatorHelper.java
public String autoAllocateAnimalsAndGetReport() {
    StringBuilder stringBuilder = new StringBuilder();
    List<Animal> animals = zoo.getAnimals();
    List<Enclosable> pens = zoo.getPens();
    for (Animal animal : animals) {
      if (!animal.isAssigned()) {
        for (Enclosable pen : pens) {
          if (pen.canLiveHere(animal)) {
            animal.assignToPen(pen);
            stringBuilder
                .append(String.format("%s assigned to %s \n", animal.getName(), pen.getName()));
            Log.i(TAG, String.format("Allocating %s into %s", animal.getName(), pen.getName()));
            break;
          }
        }
        if (!animal.isAssigned()) {
          // Only record failure if no suitable pen was found (i.e. still unassigned)
          Log.i(TAG, String.format("Unable to assign %s", animal.getName()));
          stringBuilder.append(String.format("No suitable pens for %s\n", animal.getName()));
        }
      }
    }
    return stringBuilder.toString();
  }
/**
   * Auto allocates animals to pens and generates a report for display to user.
   *
   * @return allocation report, includes newline escape chars.
   */
Auto allocates animals to pens and generates a report for display to user.
@return allocation report, includes newline escape chars.
Auto allocates animals to pens and generates a report for display to user . @return allocation report includes newline escape chars .
public String autoAllocateAnimalsAndGetReport() {
    StringBuilder stringBuilder = new StringBuilder();
    List<Animal> animals = zoo.getAnimals();
    List<Enclosable> pens = zoo.getPens();
    for (Animal animal : animals) {
      if (!animal.isAssigned()) {
        for (Enclosable pen : pens) {
          if (pen.canLiveHere(animal)) {
            animal.assignToPen(pen);
            stringBuilder
                .append(String.format("%s assigned to %s \n", animal.getName(), pen.getName()));
            Log.i(TAG, String.format("Allocating %s into %s", animal.getName(), pen.getName()));
            break;
          }
        }
        if (!animal.isAssigned()) {
          Log.i(TAG, String.format("Unable to assign %s", animal.getName()));
          stringBuilder.append(String.format("No suitable pens for %s\n", animal.getName()));
        }
      }
    }
    return stringBuilder.toString();
  }
public String autoAllocateAnimalsAndGetReport ( ) { StringBuilder stringBuilder = new StringBuilder ( ) ; List < Animal > animals = zoo . getAnimals ( ) ; List < Enclosable > pens = zoo . getPens ( ) ; for ( Animal animal : animals ) { if ( ! animal . isAssigned ( ) ) { for ( Enclosable pen : pens ) { if ( pen . canLiveHere ( animal ) ) { animal . assignToPen ( pen ) ; stringBuilder . append ( String . format ( "%s assigned to %s \n" , animal . getName ( ) , pen . getName ( ) ) ) ; Log . i ( TAG , String . format ( "Allocating %s into %s" , animal . getName ( ) , pen . getName ( ) ) ) ; break ; } } if ( ! animal . isAssigned ( ) ) { Log . i ( TAG , String . format ( "Unable to assign %s" , animal . getName ( ) ) ) ; stringBuilder . append ( String . format ( "No suitable pens for %s\n" , animal . getName ( ) ) ) ; } } } return stringBuilder . toString ( ) ; }
Auto allocates animals to pens and generates a report for display to user.
Auto allocates animals to pens and generates a report for display to user .
// Only record failure if no suitable pen was found (i.e. still unassigned)