code: private static TaskEntity getTask(final int taskId, final Collection<TaskEntity> tasks) {
      for (final TaskEntity task : tasks) {
        if (taskId == task.getId()) {
          return task;
        }
      }
      return null;
    }
docs: Iterate over the collection to find a TaskEntity with ID.