Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / checkers / CursorChecker.java
blob53bb67497ace67469fb7b1f9229de58ad1624eb3
1 // Copyright 2012 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.search.checkers;
5 /**
6 * Checks values of {@link com.google.appengine.api.search.Cursor}.
8 */
9 public final class CursorChecker {
11 /**
12 * The maximum length of a cursor.
14 public static final int MAXIMUM_CURSOR_LENGTH = 10000;
16 /**
17 * Checks the cursor string if provided is not empty nor too long.
19 * @param cursor the search cursor to check
20 * @return the checked cursor
21 * @throws IllegalArgumentException if the cursor is empty or is too long
23 public static String checkCursor(String cursor) {
24 if (cursor != null) {
25 Preconditions.checkArgument(!cursor.isEmpty(),
26 "cursor cannot be empty");
27 Preconditions.checkArgument(cursor.length() <= MAXIMUM_CURSOR_LENGTH,
28 String.format("cursor cannot be longer than %d characters", MAXIMUM_CURSOR_LENGTH));
30 return cursor;