Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / SortOptionsChecker.java
blobcbcec7272c1ba8489814fcf72fb6c47d934191d2
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 * Checks whether the limit on number of documents to score is between 0 and
17 * the maximum.
19 * @param limit the maximum number of documents to score in the search
20 * @return the checked limit
21 * @throws IllegalArgumentException if the limit is out of range
23 public static int checkLimit(int limit) {
24 Preconditions.checkArgument(limit >= 0 && limit <= SearchApiLimits.SEARCH_MAXIMUM_SORTED_LIMIT,
25 "The limit %d must be between 0 and %d", limit,
26 SearchApiLimits.SEARCH_MAXIMUM_SORTED_LIMIT);
27 return limit;
30 /**
31 * Checks the {@link ScorerSpec} is valid, specifically checking the limit
32 * on number of documents to score is not too large.
34 * @param spec the {@link ScorerSpec} to check
35 * @return the checked spec
36 * @throws IllegalArgumentException if the spec is invalid
38 public static ScorerSpec checkValid(ScorerSpec spec) {
39 checkLimit(spec.getLimit());
40 return spec;