Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / GetRequestChecker.java
blobe9757021a5f880afa97e691a66c68bdc0166c489
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 {
14 /**
15 * Checks whether the number of documents to return is between 0 and the
16 * maximum.
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
21 * is out of range
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));
27 return limit;
30 /**
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)) {
39 return startDocId;
41 return DocumentChecker.checkDocumentId(startDocId);
44 /**
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
50 * invalid
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());
60 return params;