public class ParserUtility extends Object
| Constructor and Description |
|---|
ParserUtility() |
| Modifier and Type | Method and Description |
|---|---|
static String |
dateTimeUtcToString(Date date)
Helper to convert the provided Date UTC into String.
|
static String |
getDateStringFromDate(Date date)
Convert from a date object back into a string representation
Expected format of returned string:
"2016-01-21T11:05:21"
|
static Date |
getDateTimeUtc(String dataTime)
Helper to convert the provided string in a UTC Date.
|
static List<Object> |
getJsonArrayValue(com.google.gson.JsonArray jsonArray) |
static Map<String,Object> |
getJsonObjectValue(com.google.gson.JsonObject jsonObject) |
static Object |
getJsonPrimitiveValue(com.google.gson.JsonPrimitive jsonPrimitive) |
static com.google.gson.JsonElement |
mapToJsonElement(Map<String,Object> map)
Helper to convert a provided map in to a JsonElement, including sub-maps.
|
static Object |
resolveJsonElement(com.google.gson.JsonElement jsonElement) |
static Date |
stringToDateTimeOffset(String dateTime)
Helper to convert the provided string in a offset Date.
|
static void |
validateBlobName(String blobName)
Helper to validate if the provided blob name is not null, empty, and valid.
|
static void |
validateHostName(String hostName)
Validate if a provided host name is valid using the follow criteria.
|
static void |
validateId(String id)
Validate if a provided ID is valid using the follow criteria.
|
static void |
validateKey(String key,
boolean isMetadata)
Helper to validate if the provided string is a valid json key.
|
static void |
validateMap(Map<String,Object> map,
int maxLevel,
boolean allowMetadata)
Helper to validate if the provided map in terms of maximum
levels and optionally if the keys ar not metadata.
|
static void |
validateObject(Object val)
Helper to validate if the provided object is not null.
|
static void |
validateQuery(String query)
Validates if query contains select and from keywords and also if it is a valid utf-8 string
|
static void |
validateStringUTF8(String str)
Helper to validate if the provided string is not null, empty, and all characters are UTF-8.
|
public static void validateStringUTF8(String str) throws IllegalArgumentException
str - is the string to be validated.IllegalArgumentException - if the string do not fit the criteria.public static void validateQuery(String query) throws IllegalArgumentException
query - query to be validatedIllegalArgumentException - if query does not contain "select" or "from" or is not a valid utf-8 stringpublic static void validateBlobName(String blobName) throws IllegalArgumentException
blobName - is the blob name to be validated.IllegalArgumentException - if the blob name do not fit the criteria.public static void validateObject(Object val) throws IllegalArgumentException
val - is the object to be validated.IllegalArgumentException - if the object do not fit the criteria.public static void validateKey(String key, boolean isMetadata) throws IllegalArgumentException
key - is the string to be validated.isMetadata - defines if the key belongs to a metadata, which allows character `$`.IllegalArgumentException - if the string do not fit the criteria.public static void validateMap(Map<String,Object> map, int maxLevel, boolean allowMetadata) throws IllegalArgumentException
map - the Map to be validate. It can be null, and it will succeed in this case.maxLevel - the max number of level allowed in the map.allowMetadata - the boolean that indicates if the key can contain metadata `$` or not.IllegalArgumentException - If the Map contains more than maxLevel levels or do not allow metadata
but contains metadata key.public static void validateId(String id) throws IllegalArgumentException
id - is the ID to testIllegalArgumentException - if the ID do not fits the criteriapublic static void validateHostName(String hostName) throws IllegalArgumentException
hostName - is the host name to testIllegalArgumentException - if the provided host name do not fits the criteriapublic static Date getDateTimeUtc(String dataTime) throws IllegalArgumentException
dataTime - is the string with the date and timeIllegalArgumentException - if the date and time in the string is not in the correct format.public static Date stringToDateTimeOffset(String dateTime) throws IllegalArgumentException
dateTime - is the string with the date and timeIllegalArgumentException - if the date and time in the string is not in the correct format.public static String dateTimeUtcToString(Date date) throws IllegalArgumentException
date - is the Date with the date and timeString with the date and time using the UTC format.IllegalArgumentException - if the provided date is null.public static String getDateStringFromDate(Date date) throws IllegalArgumentException
date - the date to convert into a stringIllegalArgumentException - if the provided date is nullpublic static com.google.gson.JsonElement mapToJsonElement(Map<String,Object> map) throws IllegalArgumentException
map - is the map to serializeIllegalArgumentException - if the provided map is null.public static Object resolveJsonElement(com.google.gson.JsonElement jsonElement)
public static Object getJsonPrimitiveValue(com.google.gson.JsonPrimitive jsonPrimitive)
public static Map<String,Object> getJsonObjectValue(com.google.gson.JsonObject jsonObject)
Copyright © 2019. All rights reserved.