Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / FacetQueryChecker.java
blobd84c97480359efd2581263875d881b8958222ea2
1 package com.google.appengine.api.search.checkers;
3 import com.google.apphosting.api.AppEngineInternal;
5 /**
6 * Provides checks for faceted search related query options.
8 */
9 @AppEngineInternal
10 public class FacetQueryChecker {
12 private static void checkMaximum(int number, int max, String context) {
13 Preconditions.checkArgument(number > 0, "%s should be positive", context);
14 Preconditions.checkArgument(number <= max,
15 "%s must be less than or equal to %s", context, max);
18 /**
19 * Checks that a discovery limit is valid. The value must
20 * be greater than 0 and less than {@link SearchApiLimits#FACET_MAXIMUM_DISCOVERY_LIMIT}.
22 * @param value the discovery limit to check
23 * @return the discovery limit
24 * @throws IllegalArgumentException if the discovery limit is less than 1 or
25 * greater than {@literal SearchApiLimits#FACET_MAXIMUM_DISCOVERY_LIMIT}.
27 public static int checkDiscoveryLimit(int value) {
28 checkMaximum(value, SearchApiLimits.FACET_MAXIMUM_DISCOVERY_LIMIT,
29 "Facet discovery limit");
30 return value;
33 /**
34 * Checks that a value constraint is valid. The Value length must
35 * be greater than 0 and less than {@link SearchApiLimits#FACET_MAXIMUM_VALUE_LENGTH}.
37 * @param value the value constraint to check
38 * @return the value constraint
39 * @throws IllegalArgumentException if the Value length is less than 1 or
40 * greater than {@literal SearchApiLimits#FACET_MAXIMUM_VALUE_LENGTH}.
42 public static String checkFacetValue(String value) {
43 return FacetChecker.checkAtom(value);
46 /**
47 * Checks that a facet depth option is valid. The facet depth must
48 * be greater than 0 and less than {@link SearchApiLimits#FACET_MAXIMUM_DEPTH}.
50 * @param value the facet depth option to check
51 * @return the facet depth
52 * @throws IllegalArgumentException if the facet depth option is less than 1 or
53 * greater than {@literal SearchApiLimits#FACET_MAXIMUM_DEPTH}.
55 public static Integer checkDepth(Integer value) {
56 if (value != null) {
57 checkMaximum(value, SearchApiLimits.FACET_MAXIMUM_DEPTH, "Facet depth option");
59 return value;
62 /**
63 * Checks whether discovery value limit option is valid. The discovery value limit must
64 * be greater than 0 and less than {@link SearchApiLimits#FACET_MAXIMUM_VALUE_LIMIT}.
66 * @param value the discovery value limit to check
67 * @return the discovery value limit
68 * @throws IllegalArgumentException if the discovery value limit is less than 1 or
69 * greater than {@literal SearchApiLimits#FACET_MAXIMUM_VALUE_LIMIT}.
71 public static Integer checkDiscoveryValueLimit(Integer value) {
72 if (value != null) {
73 checkMaximum(value, SearchApiLimits.FACET_MAXIMUM_VALUE_LIMIT,
74 "Facet discovery value limit");
76 return value;
79 /**
80 * Checks whether a value limit option is valid. The value limit must
81 * be greater than 0 and less than {@link SearchApiLimits#FACET_MAXIMUM_VALUE_LIMIT}.
83 * @param value the value limit to check
84 * @return the value limit
85 * @throws IllegalArgumentException if the value limit is less than 1 or
86 * greater than {@literal SearchApiLimits#FACET_MAXIMUM_VALUE_LIMIT}.
88 public static Integer checkValueLimit(Integer value) {
89 if (value != null) {
90 checkMaximum(value, SearchApiLimits.FACET_MAXIMUM_VALUE_LIMIT, "Facet value limit");
92 return value;
95 private FacetQueryChecker() {