Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / SortOptionsChecker.java
bloba0fc1394b53efaa0418fc283175552b20063a575
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.search.checkers;
5 import com.google.appengine.api.search.SearchServicePb.ScorerSpec;
7 /**
8 * Checks the values of a {@link SortOptions}.
11 public class SortOptionsChecker {
13 /**
14 * The maximum number of documents that can be requested to be scored.
16 public static final int MAXIMUM_LIMIT = 10000;
18 /**
19 * The default number of documents to score.
21 public static final int DEFAULT_LIMIT = 1000;
23 /**
24 * Checks whether the limit on number of documents to score is between 0 and
25 * the maximum.
27 * @param limit the maximum number of documents to score in the search
28 * @return the checked limit
29 * @throws IllegalArgumentException if the limit is out of range
31 public static int checkLimit(int limit) {
32 Preconditions.checkArgument(limit >= 0 && limit <= MAXIMUM_LIMIT,
33 "The limit %d must be between 0 and %d", limit, MAXIMUM_LIMIT);
34 return limit;
37 /**
38 * Checks the {@link ScorerSpec} is valid, specifically checking the limit
39 * on number of documents to score is not too large.
41 * @param spec the {@link ScorerSpec} to check
42 * @return the checked spec
43 * @throws IllegalArgumentException if the spec is invalid
45 public static ScorerSpec checkValid(ScorerSpec spec) {
46 checkLimit(spec.getLimit());
47 return spec;