你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Tools Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.service.Tools

public class Tools

Collection of static helper functions

Constructor Summary

Constructor Description
Tools()

Method Summary

Modifier and Type Method and Description
static void appendJsonAttribute(StringBuilder strBuilder, String name, String value, Boolean isQuoted, Boolean isLast)

Helper function to properly craft Json string of key-value pair

static boolean areEqual(Object a, Object b)

Equality check for objects that accounts for null value comparisons.

static long getNumberValueFromJsonObject(JsonObject jsonObject, String key)

Helper function to get numeric value from a JsonObject

static java.lang.String getValueFromJsonObject(JsonObject jsonObject, String key)

Helper function to get a value from the given JsonObject if the key name exists

static java.lang.String getValueFromJsonString(JsonString jsonString)

Helper function to get trim the leading and trailing parenthesis from a Json string if they exists

static java.lang.String getValueStringByKey(Map<String,?> map, String keyName)

Helper function to get a value from the given Map if the key name exists

static java.lang.Boolean isNullOrEmpty(String value)

Helper function to check if the input string is null or empty

static java.lang.Boolean isNullOrWhiteSpace(String value)

Helper function to check if the input string is null or contains only whitespace(s)

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

Tools

public Tools()

Method Details

appendJsonAttribute

public static void appendJsonAttribute(StringBuilder strBuilder, String name, String value, Boolean isQuoted, Boolean isLast)

Helper function to properly craft Json string of key-value pair

Parameters:

strBuilder - The StringBuilder to work on
name - The name of the key
value - The value of the key
isQuoted - If true leading and trailing quotes will be added
isLast - If false trailing comma will added

areEqual

public static boolean areEqual(Object a, Object b)

Equality check for objects that accounts for null value comparisons. If both objects are null, this will return false. Both objects must have .equals(...) implemented correctly for this method to work properly.

Parameters:

a - the first object
b - the seconds object

Returns:

if the two are equal

getNumberValueFromJsonObject

public static long getNumberValueFromJsonObject(JsonObject jsonObject, String key)

Helper function to get numeric value from a JsonObject

Parameters:

jsonObject - The JsonObject object to get the value from
key - The name of the key

Returns:

The numeric value

getValueFromJsonObject

public static String getValueFromJsonObject(JsonObject jsonObject, String key)

Helper function to get a value from the given JsonObject if the key name exists

Parameters:

jsonObject - The JsonObject object to get the value from
key - The name of the key

Returns:

The value of the given key if exists otherwise empty string

getValueFromJsonString

public static String getValueFromJsonString(JsonString jsonString)

Helper function to get trim the leading and trailing parenthesis from a Json string if they exists

Parameters:

jsonString - The JsonString to trim

Returns:

The trimmed string

getValueStringByKey

public static String getValueStringByKey(Map map, String keyName)

Helper function to get a value from the given Map if the key name exists

Parameters:

map - The Map object to get the value from
keyName - The name of the key

Returns:

The value of the given key if exists otherwise empty string

isNullOrEmpty

public static Boolean isNullOrEmpty(String value)

Helper function to check if the input string is null or empty

Parameters:

value - The string to check

Returns:

The value true if the input string is empty or null

isNullOrWhiteSpace

public static Boolean isNullOrWhiteSpace(String value)

Helper function to check if the input string is null or contains only whitespace(s)

Parameters:

value - The string to check

Returns:

The value true if the input string is empty or contains only whitespace(s)

Applies to