2323import java .util .List ;
2424
2525/**
26- * This class holds a single result of a batch call. {@code T} is the type of the result and {@code
27- * E} is the type of the service-dependent exception thrown when a processing error occurs.
26+ * This class holds a single result of a batch call. The class is not thread-safe.
27+ *
28+ * @param <T> the type of the result
29+ * @param <E> the type of the service-dependent exception thrown when a processing error occurs
30+ *
2831 */
2932public abstract class BatchResult <T , E extends BaseServiceException > {
3033
@@ -45,7 +48,7 @@ public boolean completed() {
4548 * Returns the result of this call.
4649 *
4750 * @throws IllegalStateException if the batch has not been completed yet
48- * @throws E if an error occurred when processing this request
51+ * @throws E if an error occurred when processing the batch request
4952 */
5053 public T get () throws E {
5154 checkState (completed (), "Batch has not been completed yet" );
@@ -61,18 +64,16 @@ public T get() throws E {
6164 * @throws IllegalStateException if the batch has been completed already
6265 */
6366 public void notify (Callback <T , E > callback ) {
64- if (completed ) {
65- throw new IllegalStateException ("The batch has been completed. All the calls to the notify()"
67+ checkState (!completed , "The batch has been completed. All the calls to the notify()"
6668 + " method should be done prior to submitting the batch." );
67- }
6869 toBeNotified .add (callback );
6970 }
7071
7172 /**
7273 * Sets an error and status as completed. Notifies all callbacks.
7374 */
7475 protected void error (E error ) {
75- this .error = error ;
76+ this .error = checkNotNull ( error ) ;
7677 this .completed = true ;
7778 for (Callback <T , E > callback : toBeNotified ) {
7879 callback .error (error );
0 commit comments