コード例 #1
0
  /**
   * Gets a collection of malfunctionable entities local to the given person.
   *
   * @return collection collection of malfunctionables.
   */
  public static Collection<Malfunctionable> getMalfunctionables(Person person) {

    Collection<Malfunctionable> entities = new ArrayList<Malfunctionable>();
    LocationSituation location = person.getLocationSituation();

    if (location == LocationSituation.IN_SETTLEMENT) {
      entities = getMalfunctionables(person.getSettlement());
    }

    if (location == LocationSituation.IN_VEHICLE) {
      entities = getMalfunctionables(person.getVehicle());
    }

    Collection<Unit> inventoryUnits = person.getInventory().getContainedUnits();
    if (inventoryUnits.size() > 0) {
      Iterator<Unit> i = inventoryUnits.iterator();
      while (i.hasNext()) {
        Unit unit = i.next();
        if ((unit instanceof Malfunctionable) && !entities.contains(unit)) {
          entities.add((Malfunctionable) unit);
        }
      }
    }

    return entities;
  }