Package org.gbif.api.util
Class SearchTypeValidator
- java.lang.Object
-
- org.gbif.api.util.SearchTypeValidator
-
public class SearchTypeValidator extends Object
Utility class to do basic validation of all search enum based values.
-
-
Field Summary
Fields Modifier and Type Field Description static String
SIMPLE_ISO_YEAR_MONTH_PATTERN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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.static Range<LocalDate>
parseDateRange(String value)
Parses a range of ISO dates.static Range<Double>
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.static Range<Integer>
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 Detail
-
SIMPLE_ISO_YEAR_MONTH_PATTERN
public static final String SIMPLE_ISO_YEAR_MONTH_PATTERN
- See Also:
- Constant Field Values
-
-
Method Detail
-
isNumericRange
public static boolean isNumericRange(String value)
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
public static 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.- Returns:
- true if the given value is a valid date range
-
parseDateRange
public static Range<LocalDate> parseDateRange(String value)
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
public static Range<Double> parseDecimalRange(String value)
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
public static Range<Integer> parseIntegerRange(String value)
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
public static void validate(SearchParameter param, String value) throws IllegalArgumentException
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
public static void validateGeoDistance(String latitude, String longitude, String distance)
-
parseDistanceRange
public static Range<DistanceUnit.Distance> parseDistanceRange(String value)
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
public static DistanceUnit.Distance parseDistance(String distance)
-
-