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
.common
.base
.Strings
;
9 * Checks values of {@link com.google.appengine.api.search.GetRequest}.
12 public class GetRequestChecker
{
15 * Checks whether the number of documents to return is between 0 and the
18 * @param limit the maximum number of documents to return in results list
19 * @return the checked number of documents to return
20 * @throws IllegalArgumentException if the number of documents to return
23 public static int checkLimit(int limit
) {
24 Preconditions
.checkArgument(limit
>= 0 && limit
<= SearchApiLimits
.GET_RANGE_MAXIMUM_LIMIT
,
25 String
.format("The limit %d must be between 0 and %d",
26 limit
, SearchApiLimits
.GET_RANGE_MAXIMUM_LIMIT
));
31 * Checks whether the given start document Is legal.
33 * @param startDocId the start ocument Id to be checked.
34 * @return the checked start document Id.
35 * @throws IllegalArgumentException if the start document Id is illegal.
37 public static String
checkStartDocId(String startDocId
) {
38 if (Strings
.isNullOrEmpty(startDocId
)) {
41 return DocumentChecker
.checkDocumentId(startDocId
);
45 * Checks the values of the {@link ListDocumentsParams} params.
47 * @param params The {@link ListDocumentsParams} to check
48 * @return the checked params
49 * @throws IllegalArgumentException if some of the values of params are
52 public static ListDocumentsParams
checkListDocumentsParams(ListDocumentsParams params
) {
53 IndexChecker
.checkName(params
.getIndexSpec().getName());
54 if (params
.hasLimit()) {
55 checkLimit(params
.getLimit());
57 if (params
.hasStartDocId()) {
58 DocumentChecker
.checkDocumentId(params
.getStartDocId());