ParserUtility Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.provisioning.service.configs.ParserUtility

public class ParserUtility

Set of static functions to help the serializer.

Method Summary

Modifier and Type Method and Description
String dateTimeUtcToString(Date date)

Helper to convert the provided Date UTC into String. Expected result: "2016-06-01T21:22:43.799Z"

Date getDateTimeUtc(String dataTime)

Helper to convert the provided string in a UTC Date. Expected format: "2016-06-01T21:22:43.7996883Z"

Map<String, Object> getJsonObjectValue(JsonObject jsonObject)
String getUTCDateStringFromDate(Date date)

Convert from a date object back into a string representation Expected format of returned string: "2016-01-21T11:05:21"

JsonElement mapToJsonElement(Map<String, Object> map)

Helper to convert a provided map in to a JsonElement, including sub-maps.

Object resolveJsonElement(JsonElement jsonElement)
Date stringToDateTimeOffset(String dateTime)

Helper to convert the provided string in a offset Date. Expected format: "2016-06-01T21:22:41+00:00"

void validateBlobName(String blobName)

Helper to validate if the provided blob name is not null, empty, and valid.

void validateMap(Map<String, Object> map)

Helper to validate if the provided map in terms of maximum levels and optionally if the keys ar not metadata.

void validateObject(Object val)

Helper to validate if the provided object is not null.

void validateQuery(String query)

Validates if query contains select and from keywords and also if it is a valid utf-8 string

void validateStringUTF8(String str)

Helper to validate if the provided string is not null, empty, and all characters are UTF-8.

Method Details

dateTimeUtcToString

public static String dateTimeUtcToString(Date date)

Helper to convert the provided Date UTC into String. Expected result: "2016-06-01T21:22:43.799Z"

Parameters:

date -

is theDate 

</code> with the date and time </p>

Returns:

theString 

</code> with the date and time using the UTC format. </p>

Throws:

IllegalArgumentException -

if the provided date isnull 

</code> . </p>

getDateTimeUtc

public static Date getDateTimeUtc(String dataTime)

Helper to convert the provided string in a UTC Date. Expected format: "2016-06-01T21:22:43.7996883Z"

Parameters:

dataTime - is the string with the date and time

Returns:

Date parsed from the string

Throws:

IllegalArgumentException - if the date and time in the string is not in the correct format.

getJsonObjectValue

public static Map getJsonObjectValue(JsonObject jsonObject)

Parameters:

jsonObject

getUTCDateStringFromDate

public static String getUTCDateStringFromDate(Date date)

Convert from a date object back into a string representation Expected format of returned string: "2016-01-21T11:05:21"

Parameters:

date - the date to convert into a string

Returns:

the date represented as a string

Throws:

IllegalArgumentException - if the provided date is null

mapToJsonElement

public static JsonElement mapToJsonElement(Map map)

Helper to convert a provided map in to a JsonElement, including sub-maps.

Parameters:

map - is the map to serialize

Returns:

a JsonElement that represents the content of the map.

Throws:

IllegalArgumentException - if the provided map is null.

resolveJsonElement

public static Object resolveJsonElement(JsonElement jsonElement)

Parameters:

jsonElement

stringToDateTimeOffset

public static Date stringToDateTimeOffset(String dateTime)

Helper to convert the provided string in a offset Date. Expected format: "2016-06-01T21:22:41+00:00"

Parameters:

dateTime - is the string with the date and time

Returns:

Date parsed from the string

Throws:

IllegalArgumentException - if the date and time in the string is not in the correct format.

validateBlobName

public static void validateBlobName(String blobName)

Helper to validate if the provided blob name is not null, empty, and valid.

Parameters:

blobName - is the blob name to be validated.

Throws:

IllegalArgumentException - if the blob name do not fit the criteria.

validateMap

public static void validateMap(Map map)

Helper to validate if the provided map in terms of maximum levels and optionally if the keys ar not metadata.

Parameters:

map -

theMap 

</code> to be validate. It can be<code>null 

</code> , and it will succeed in this case. </p>

Throws:

IllegalArgumentException - If the Map contains more than maxLevel levels or do not allow metadata but contains metadata key.

validateObject

public static void validateObject(Object val)

Helper to validate if the provided object is not null.

Parameters:

val - is the object to be validated.

Throws:

IllegalArgumentException - if the object do not fit the criteria.

validateQuery

public static void validateQuery(String query)

Validates if query contains select and from keywords and also if it is a valid utf-8 string

Parameters:

query - query to be validated

Throws:

IllegalArgumentException - if query does not contain "select" or "from" or is not a valid utf-8 string

validateStringUTF8

public static void validateStringUTF8(String str)

Helper to validate if the provided string is not null, empty, and all characters are UTF-8.

Parameters:

str - is the string to be validated.

Throws:

IllegalArgumentException - if the string do not fit the criteria.

Applies to