Version 1.7.4
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / SortOptionsChecker.java
blob350b73cfff62c940a5d380bddfb58d23073047da
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;
6 import com.google.apphosting.api.AppEngineInternal;
8 /**
9 * Checks the values of a {@link SortOptions}.
12 @AppEngineInternal
13 public class SortOptionsChecker {
15 /**
16 * The maximum number of documents that can be requested to be scored.
17 * @deprecated From 1.7.4, use {@link SearchApiLimits#SEARCH_MAXIMUM_SORTED_LIMIT}
19 @Deprecated public static final int MAXIMUM_LIMIT = 10000;
21 /**
22 * The default number of documents to score.
23 * @deprecated From 1.7.4, use {@link SearchApiLimits#SEARCH_DEFAULT_SORTED_LIMIT}
25 @Deprecated public static final int DEFAULT_LIMIT = 1000;
27 /**
28 * Checks whether the limit on number of documents to score is between 0 and
29 * the maximum.
31 * @param limit the maximum number of documents to score in the search
32 * @return the checked limit
33 * @throws IllegalArgumentException if the limit is out of range
35 public static int checkLimit(int limit) {
36 Preconditions.checkArgument(limit >= 0 && limit <= SearchApiLimits.SEARCH_MAXIMUM_SORTED_LIMIT,
37 "The limit %d must be between 0 and %d", limit,
38 SearchApiLimits.SEARCH_MAXIMUM_SORTED_LIMIT);
39 return limit;
42 /**
43 * Checks the {@link ScorerSpec} is valid, specifically checking the limit
44 * on number of documents to score is not too large.
46 * @param spec the {@link ScorerSpec} to check
47 * @return the checked spec
48 * @throws IllegalArgumentException if the spec is invalid
50 public static ScorerSpec checkValid(ScorerSpec spec) {
51 checkLimit(spec.getLimit());
52 return spec;