TaskManager { public AbstractTask getTask(Agent agent) { AbstractTask task; int preferredTaskIndex = -1; int index = 0; while(!tasks.isEmpty() && index < tasks.size()) { task = tasks.get(index); if((task.getLocation().getX() - 0.5) < agent.getLocation().getX() && (task.getLocation().getX() + 0.5) > agent.getLocation().getX() && (task.getLocation().getY()) > agent.getLocation().getY() && (task.getLocation().getY() - agent.getLocation().getY()) < 1.5 && (task.getLocation().getY() - agent.getLocation().getY()) > 0) { preferredTaskIndex = index; break; } index++; } index = 0; while (!tasks.isEmpty() && index < tasks.size()) { if (preferredTaskIndex >= 0) { task = tasks.get(preferredTaskIndex); index--; preferredTaskIndex = -1; } else { task = tasks.get(index); } if ((task.getAllowedWorker() == null || task.getAllowedWorker() == agent) && agent.hasRequiredTool(task)) { if (agent.isRequiredRole(task)) { tasks.remove(task); task.setWorker(agent); if (task.isValid() && !conflictingTasks(task)) { runningTasks.add(task); return task; } } else if (!agent.isRoleTypeLocked() && !AgentManager.getInstance() .suitableAgentExists(task)) { Agent.RoleType requiredRole = ((AgentRoleTask) task) .relatedRole(); World world = WorldManager.getInstance().getWorld(); return new ChangeRoleTask(requiredRole, world, false); } } index++; } return null; } TaskManager(); void setController(TaskViewerController controller); void refresh(); void setInstance(TaskManager taskManager); static TaskManager getInstance(); void addTask(AbstractTask task); @SuppressWarnings("unchecked") List<AbstractTask> listTasks(); void moveTask(AbstractTask task, String direction); boolean contains(AbstractTask task); boolean conflictingTasks(AbstractTask task); boolean hasTasks(); void removeTask(AbstractTask task); AbstractTask getTask(Agent agent); void updateTaskRoles();  }
@Test public void getTaskTest() { }