1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.search
.checkers
;
5 import com
.google
.appengine
.api
.search
.SearchServicePb
.ListDocumentsParams
;
6 import com
.google
.appengine
.api
.search
.Util
;
9 * Checks values of {@link com.google.appengine.api.search.ListRequest}.
12 public class ListRequestChecker
{
14 * The maximum number of documents which can be requested.
16 public static final int MAXIMUM_LIMIT
= 1000;
19 * The default number of documents requested.
21 public static final int DEFAULT_LIMIT
= 100;
24 * Checks whether the number of documents to return is between 0 and the
27 * @param limit the maximum number of documents to return in results list
28 * @return the checked number of documents to return
29 * @throws IllegalArgumentException if the number of documents to return
32 public static int checkLimit(int limit
) {
33 Preconditions
.checkArgument(limit
>= 0 && limit
<= MAXIMUM_LIMIT
,
34 String
.format("The limit %d must be between 0 and %d",
35 limit
, MAXIMUM_LIMIT
));
40 * Checks whether the given start document Is legal.
42 * @param startDocId the start ocument Id to be checked.
43 * @return the checked start document Id.
44 * @throws IllegalArgumentException if the start document Id is illegal.
46 public static String
checkStartDocId(String startDocId
) {
47 if (Util
.isNullOrEmpty(startDocId
)) {
50 return DocumentChecker
.checkDocumentId(startDocId
);
54 * Checks the values of the {@link ListDocumentsParams} params.
56 * @param params The {@link ListDocumentsParams} to check
57 * @return the checked params
58 * @throws IllegalArgumentException if some of the values of params are
61 public static ListDocumentsParams
checkListDocumentsParams(ListDocumentsParams params
) {
62 IndexChecker
.checkName(params
.getIndexSpec().getName());
63 if (params
.hasLimit()) {
64 checkLimit(params
.getLimit());
66 if (params
.hasStartDocId()) {
67 DocumentChecker
.checkDocumentId(params
.getStartDocId());