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