public QueryTask waitForQueryTask(URI uri,TaskState.TaskStage expectedStage){
  List<TaskState.TaskStage> finalTaskStages=Arrays.asList(TaskState.TaskStage.CANCELLED,TaskState.TaskStage.FAILED,TaskState.TaskStage.FINISHED,expectedStage);
  String error=String.format("Task did not reach expected state %s",expectedStage);
  Object[] r=new Object[1];
  final URI finalUri=uri;
  waitFor(error,null);
  return (QueryTask)r[0];
}

public QueryTask waitForQueryTask ( URI uri , TaskState . TaskStage expectedStage ) { List < TaskState . TaskStage > finalTaskStages = Arrays . asList ( TaskState . TaskStage . CANCELLED , TaskState . TaskStage . FAILED , TaskState . TaskStage . FINISHED , expectedStage ) ; String error = String . format ( "Task did not reach expected state %s" , expectedStage ) ; Object [ ] r = new Object [ 1 ] ; final URI finalUri = uri ; waitFor ( error , null ) ; return ( QueryTask ) r [ 0 ] ; }
helper method that waits for a query task to reach the expected stage
