Share via


Utils Class

  • java.lang.Object
    • com.microsoft.azure.management.resources.fluentcore.utils.Utils

public final class Utils

Defines a few utilities.

Method Summary

Modifier and Type Method and Description
static com.microsoft.azure.PagedList<OutT> <OutT,InT>toPagedList(List<InT> list, Func1<InT,OutT> mapper)

Converts the given list of a type to paged list of a different type.

static void addToListIfNotExists(List<String> list, String value)

Adds a value to the list if does not already exists.

static java.lang.String createOdataFilterForTags(String tagName, String tagValue)

Creates an Odata filter string that can be used for filtering list results by tags.

static rx.Observable<byte[]> downloadFileAsync(String url, Retrofit retrofit)

Download a file asynchronously.

static com.microsoft.azure.AzureEnvironment extractAzureEnvironment(RestClient restClient)

Try to extract the environment the client is authenticated to based on the information on the rest client.

static java.lang.String getResponseBodyInString(ResponseBody responseBody)

Get the response body as string.

static java.lang.String getStorageConnectionString(String accountName, String accountKey, RestClient restClient)

Get the Azure storage account connection string.

static void removeFromList(List<String> list, String value)

Removes a value from the list.

static java.lang.String resourceGroupId(String id)
static rx.Observable<U> rootResource(Observable<Indexable> stream)

Gets an observable of type U, where U extends Indexable, that emits only the root resource from a given observable of Indexable.

static boolean toPrimitiveBoolean(Boolean value)

Converts an object Boolean to a primitive boolean.

static int toPrimitiveInt(Integer value)

Converts an object Integer to a primitive int.

static int toPrimitiveInt(Long value)

Converts an object Long to a primitive int.

static long toPrimitiveLong(Long value)

Converts an object Long to a primitive long.

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

Method Details

<OutT,InT>toPagedList

public static PagedList toPagedList(List list, Func1 mapper)

Converts the given list of a type to paged list of a different type.

Parameters:

list - the list to convert to paged list
mapper - the mapper to map type in input list to output list

Returns:

the paged list

addToListIfNotExists

public static void addToListIfNotExists(List list, String value)

Adds a value to the list if does not already exists.

Parameters:

list - the list
value - value to add if not exists in the list

createOdataFilterForTags

public static String createOdataFilterForTags(String tagName, String tagValue)

Creates an Odata filter string that can be used for filtering list results by tags.

Parameters:

tagName - the name of the tag. If not provided, all resources will be returned.
tagValue - the value of the tag. If not provided, only tag name will be filtered.

Returns:

the Odata filter to pass into list methods

downloadFileAsync

public static Observable downloadFileAsync(String url, Retrofit retrofit)

Download a file asynchronously.

Parameters:

url - the URL pointing to the file
retrofit - the retrofit client

Returns:

an Observable pointing to the content of the file

extractAzureEnvironment

public static AzureEnvironment extractAzureEnvironment(RestClient restClient)

Try to extract the environment the client is authenticated to based on the information on the rest client.

Parameters:

restClient - the RestClient instance

Returns:

the non-null AzureEnvironment

getResponseBodyInString

public static String getResponseBodyInString(ResponseBody responseBody)

Get the response body as string.

Parameters:

responseBody - response body object

Returns:

response body in string

Throws:

java.io.IOException - throw IOException

getStorageConnectionString

public static String getStorageConnectionString(String accountName, String accountKey, RestClient restClient)

Get the Azure storage account connection string.

Parameters:

accountName - storage account name
accountKey - storage account key
restClient - rest client

Returns:

the storage account connection string.

removeFromList

public static void removeFromList(List list, String value)

Removes a value from the list.

Parameters:

list - the list
value - value to remove

resourceGroupId

public static String resourceGroupId(String id)

Parameters:

id - resource id

Returns:

resource group id for the resource id provided

rootResource

public static Observable rootResource(Observable stream)

Gets an observable of type U, where U extends Indexable, that emits only the root resource from a given observable of Indexable.

Parameters:

stream - the input observable of Indexable

Returns:

an observable that emits last item

toPrimitiveBoolean

public static boolean toPrimitiveBoolean(Boolean value)

Converts an object Boolean to a primitive boolean.

Parameters:

value - the Boolean value

Returns:

false if the given Boolean value is null or false else true

toPrimitiveInt

public static int toPrimitiveInt(Integer value)

Converts an object Integer to a primitive int.

Parameters:

value - the Integer value

Returns:

0 if the given Integer value is null else integer value

toPrimitiveInt

public static int toPrimitiveInt(Long value)

Converts an object Long to a primitive int.

Parameters:

value - the Long value

Returns:

0 if the given Long value is null else integer value

toPrimitiveLong

public static long toPrimitiveLong(Long value)

Converts an object Long to a primitive long.

Parameters:

value - the Long value

Returns:

0 if the given Long value is null else long value

Applies to