Package org.gbif.api.util
Class SearchTypeValidator
java.lang.Object
org.gbif.api.util.SearchTypeValidator
Utility class to do basic validation of all search enum based values.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isDateRange
(String value) Determines whether the value given is a valid date range or low precision (year, year-month) date, delimiting two values by a comma.static boolean
isNumericRange
(String value) Determines whether the value given is a valid numeric range, delimiting two values by a comma.parseDateRange
(String value) Parses a range of ISO dates.parseDecimalRange
(String value) Parses a decimal range in the format 123.1,456.static DistanceUnit.Distance
parseDistance
(String distance) static Range<DistanceUnit.Distance>
parseDistanceRange
(String value) Parses a distance range in the format 123m,456km.parseIntegerRange
(String value) Parses an integer range in the format 123,456static void
validate
(SearchParameter param, String value) Validates that a given parameter value matches the expected type of the parameter as defined bySearchParameter.type()
and throws an IllegalArgumentException otherwise.static void
validateGeoDistance
(String latitude, String longitude, String distance)
-
Field Details
-
SIMPLE_ISO_YEAR_MONTH_PATTERN
- See Also:
-
-
Method Details
-
isNumericRange
Determines whether the value given is a valid numeric range, delimiting two values by a comma.- Returns:
- true if the given value is a valid range
-
isDateRange
Determines whether the value given is a valid date range or low precision (year, year-month) date, delimiting two values by a comma.- Returns:
- true if the given value is a valid date range
-
parseDateRange
Parses a range of ISO dates. The date format used is the first date format that successfully parses the lower range limit.- Returns:
- the parsed range with wildcards represented as null values
- Throws:
IllegalArgumentException
- if value is invalid or null
-
parseDecimalRange
Parses a decimal range in the format 123.1,456.- Returns:
- the parsed range with wildcards represented as null values
- Throws:
IllegalArgumentException
- if value is invalid or null
-
parseIntegerRange
Parses an integer range in the format 123,456- Returns:
- the parsed range with wildcards represented as null values
- Throws:
IllegalArgumentException
- if value is invalid or null
-
validate
Validates that a given parameter value matches the expected type of the parameter as defined bySearchParameter.type()
and throws an IllegalArgumentException otherwise.- Parameters:
param
- the search parameter defining the expected typevalue
- the parameter value to be validated- Throws:
IllegalArgumentException
- if the value cannot be converted to the expected type
-
validateGeoDistance
-
parseDistanceRange
Parses a distance range in the format 123m,456km.- Returns:
- the parsed range with wildcards represented as null values
- Throws:
IllegalArgumentException
- if value is invalid or null
-
parseDistance
-