Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / GetRequestChecker.java
blobb379096b5221e1ab1a154cf08d6457b52f95f369
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;
8 /**
9 * Checks values of {@link com.google.appengine.api.search.GetRequest}.
12 public class GetRequestChecker {
13 /**
14 * The maximum number of documents which can be requested.
15 * @deprecated From 1.7.4, use {@link SearchApiLimits#GET_RANGE_MAXIMUM_LIMIT}
17 @Deprecated public static final int MAXIMUM_LIMIT = 1000;
19 /**
20 * The default number of documents requested.
21 * @deprecated From 1.7.4, use {@link SearchApiLimits#GET_RANGE_MAXIMUM_LIMIT}
23 @Deprecated public static final int DEFAULT_LIMIT = 100;
25 /**
26 * Checks whether the number of documents to return is between 0 and the
27 * maximum.
29 * @param limit the maximum number of documents to return in results list
30 * @return the checked number of documents to return
31 * @throws IllegalArgumentException if the number of documents to return
32 * is out of range
34 public static int checkLimit(int limit) {
35 Preconditions.checkArgument(limit >= 0 && limit <= SearchApiLimits.GET_RANGE_MAXIMUM_LIMIT,
36 String.format("The limit %d must be between 0 and %d",
37 limit, SearchApiLimits.GET_RANGE_MAXIMUM_LIMIT));
38 return limit;
41 /**
42 * Checks whether the given start document Is legal.
44 * @param startDocId the start ocument Id to be checked.
45 * @return the checked start document Id.
46 * @throws IllegalArgumentException if the start document Id is illegal.
48 public static String checkStartDocId(String startDocId) {
49 if (Strings.isNullOrEmpty(startDocId)) {
50 return startDocId;
52 return DocumentChecker.checkDocumentId(startDocId);
55 /**
56 * Checks the values of the {@link ListDocumentsParams} params.
58 * @param params The {@link ListDocumentsParams} to check
59 * @return the checked params
60 * @throws IllegalArgumentException if some of the values of params are
61 * invalid
63 public static ListDocumentsParams checkListDocumentsParams(ListDocumentsParams params) {
64 IndexChecker.checkName(params.getIndexSpec().getName());
65 if (params.hasLimit()) {
66 checkLimit(params.getLimit());
68 if (params.hasStartDocId()) {
69 DocumentChecker.checkDocumentId(params.getStartDocId());
71 return params;