Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / PutResponse.java
blobd44d7bc3440eea90cfe2f3b9a72be76de725cd3b
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.search;
5 import com.google.appengine.api.search.checkers.Preconditions;
7 import java.io.Serializable;
8 import java.util.Collections;
9 import java.util.Iterator;
10 import java.util.List;
12 /**
13 * Represents a result of putting a list of objects (documents or queries)
14 * into an index. The response contains a list of {@link OperationResult}
15 * indicating success or not of putting each of the objects into the index,
16 * and a list of Id of the objects which are those given in the request or
17 * allocated by the search service to those objects which do not have an
18 * Id supplied.
20 public class PutResponse implements Iterable<OperationResult>, Serializable {
21 private static final long serialVersionUID = 3063892804095727768L;
23 private final List<OperationResult> results;
24 private final List<String> ids;
26 /**
27 * Creates a {@link PutResponse} by specifying a list of
28 * {@link OperationResult} and a list of document or query ids.
30 * @param results a list of {@link OperationResult} that indicate the
31 * success or not putting each object into the index
32 * @param ids a list of Id of objects that were requested to be
33 * put into the index. The search service may supply Ids for those objects
34 * where none was supplied
36 protected PutResponse(List<OperationResult> results, List<String> ids) {
37 this.results = Collections.unmodifiableList(
38 Preconditions.checkNotNull(results, "results cannot be null"));
39 this.ids = Collections.unmodifiableList(
40 Preconditions.checkNotNull(ids, "ids cannot be null"));
43 @Override
44 public Iterator<OperationResult> iterator() {
45 return results.iterator();
48 /**
49 * @return an unmodifiable list of {@link OperationResult} indicating
50 * whether each {@link Document} was put or not
52 public List<OperationResult> getResults() {
53 return results;
56 /**
57 * @return an unmodifiable list of Ids
59 public List<String> getIds() {
60 return ids;
63 @Override
64 public String toString() {
65 return new Util.ToStringHelper("PutResponse")
66 .addIterableField("results", getResults(), 0)
67 .addIterableField("ids", getIds(), 0)
68 .finish();