App Engine Python SDK version 1.7.4 (2)
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / ListRequestChecker.java
blob63511059776f4327da9fc3665ae44446c0e6d9f2
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;
8 /**
9 * Checks values of {@link com.google.appengine.api.search.ListRequest}.
12 public class ListRequestChecker {
13 /**
14 * The maximum number of documents which can be requested.
16 public static final int MAXIMUM_LIMIT = 1000;
18 /**
19 * The default number of documents requested.
21 public static final int DEFAULT_LIMIT = 100;
23 /**
24 * Checks whether the number of documents to return is between 0 and the
25 * maximum.
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
30 * is out of range
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));
36 return limit;
39 /**
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)) {
48 return startDocId;
50 return DocumentChecker.checkDocumentId(startDocId);
53 /**
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
59 * invalid
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());
69 return params;