Class FieldChecker
- java.lang.Object
-
- com.google.appengine.api.search.checkers.FieldChecker
-
public final class FieldChecker extends Object
Provides checks for Field names, language code, and values: text, HTML, atom or date.
-
-
Constructor Summary
Constructors Constructor Description FieldChecker()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcheckAtom(String atom)Checks whether an atom is valid.static DatecheckDate(Date date)Checks whether a date is within range.static StringcheckExpression(String expression)Checks whether a field expression is not null and is parsable.static StringcheckFieldName(String name)Checks whether a field name is valid.static StringcheckFieldName(String name, String fieldName)Checks whether a field name is valid.static StringcheckHTML(String html)Checks whether a html is valid.static DoublecheckNumber(Double value)Checks whether a number is valid.static StringcheckPrefix(String prefix)Checks whether a prefix field is valid.static StringcheckSortExpression(String expression)Checks whether a sort bexpression is not null and is parsable.static StringcheckText(String text)Checks whether a text is valid.static com.google.apphosting.api.search.DocumentPb.FieldcheckValid(com.google.apphosting.api.search.DocumentPb.Field field)static List<Double>checkVector(List<Double> vector)Checks whether a vector field is valid.static LocaleparseLocale(String locale)Returns aLocaleparsed from the given locale string.
-
-
-
Method Detail
-
checkFieldName
public static String checkFieldName(String name)
Checks whether a field name is valid. The field name length must be between 1 andSearchApiLimits.MAXIMUM_NAME_LENGTHand it should matchSearchApiLimits.FIELD_NAME_PATTERN.- Parameters:
name- the field name to check- Returns:
- the checked field name
- Throws:
IllegalArgumentException- if the field name is null or empty or is longer than SearchApiLimits#MAXIMUM_NAME_LENGTH or it doesn't match #FIELD_NAME_PATTERN.
-
checkFieldName
public static String checkFieldName(String name, String fieldName)
Checks whether a field name is valid. The field name length must be between 1 andSearchApiLimits.MAXIMUM_NAME_LENGTHand it should matchSearchApiLimits.FIELD_NAME_PATTERN.- Parameters:
name- the field name to checkfieldName- the name of the Java field name of the class where name is checked- Returns:
- the checked field name
- Throws:
IllegalArgumentException- if the field name is null or empty or is longer than Field.MAXIMUM_NAME_LENGTH or it doesn't match #FIELD_NAME_PATTERN.
-
checkText
public static String checkText(String text)
Checks whether a text is valid. A text can be null, or a string between 0 and SearchApiLimits.MAXIMUM_TEXT_LENGTH in length.- Parameters:
text- the text to check- Returns:
- the checked text
- Throws:
IllegalArgumentException- if text is too long
-
checkHTML
public static String checkHTML(String html)
Checks whether a html is valid. A html can be null or a string between 0 and SearchApiLimits.MAXIMUM_TEXT_LENGTH in length.- Parameters:
html- the html to check- Returns:
- the checked html
- Throws:
IllegalArgumentException- if html is too long
-
checkAtom
public static String checkAtom(String atom)
Checks whether an atom is valid. An atom can be null or a string between 1 and SearchApiLimits.MAXIMUM_ATOM_LENGTH in length.- Parameters:
atom- the atom to check- Returns:
- the checked atom
- Throws:
IllegalArgumentException- if atom is too long
-
checkPrefix
public static String checkPrefix(String prefix)
Checks whether a prefix field is valid. A prefix field can be null or a string between 1 and SearchApiLimits.MAXIMUM_PREFIX_LENGTH in length.- Parameters:
prefix- the prefix to check- Returns:
- the checked prefix
- Throws:
IllegalArgumentException- if prefix is too long
-
checkVector
public static List<Double> checkVector(List<Double> vector)
Checks whether a vector field is valid. A vector field can be an array of any number with size less than SearchApiLimits.VECTOR_FIELD_MAX_SIZE.- Parameters:
vector- the vector to check- Throws:
IllegalArgumentException- if vector is too long.
-
checkNumber
public static Double checkNumber(Double value)
Checks whether a number is valid. A number can be null or a value betweenSearchApiLimits.MINIMUM_NUMBER_VALUEandSearchApiLimits.MAXIMUM_NUMBER_VALUE, inclusive.- Parameters:
value- the value to check- Returns:
- the checked number
- Throws:
IllegalArgumentException- if number is out of range
-
checkDate
public static Date checkDate(Date date) throws IllegalArgumentException
Checks whether a date is within range. Date is nullable.- Parameters:
date- the date to check- Returns:
- the checked date
- Throws:
IllegalArgumentException- if date is out of range
-
checkExpression
public static String checkExpression(String expression)
Checks whether a field expression is not null and is parsable.- Parameters:
expression- the expression to check- Returns:
- the checked expression
- Throws:
IllegalArgumentException- if the expression is null, or cannot be parsed
-
checkSortExpression
public static String checkSortExpression(String expression)
Checks whether a sort bexpression is not null and is parsable.- Parameters:
expression- the expression to check- Returns:
- the checked expression
- Throws:
IllegalArgumentException- if the expression is null, or cannot be parsed
-
checkValid
public static com.google.apphosting.api.search.DocumentPb.Field checkValid(com.google.apphosting.api.search.DocumentPb.Field field)
-
-