All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.management.network.implementation.AvailableProvidersImpl Maven / Gradle / Ivy

There is a newer version: 1.41.4
Show newest version
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */
package com.microsoft.azure.management.network.implementation;

import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.network.AvailableProviders;
import com.microsoft.azure.management.network.AvailableProvidersListCountry;
import com.microsoft.azure.management.network.AvailableProvidersListParameters;
import com.microsoft.azure.management.network.NetworkWatcher;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.ExecutableImpl;
import rx.Observable;
import rx.functions.Func1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * The implementation of AvailableProviders.
 */
@LangDefinition
class AvailableProvidersImpl extends ExecutableImpl
        implements AvailableProviders,
        AvailableProviders.Definition {
    private Map providersByCountry;
    private final NetworkWatcherImpl parent;
    private AvailableProvidersListParameters parameters = new AvailableProvidersListParameters();
    private AvailableProvidersListInner inner;

    AvailableProvidersImpl(NetworkWatcherImpl parent) {
        this.parent = parent;
    }

    @Override
    public AvailableProvidersListParameters availableProvidersParameters() {
        return parameters;
    }

    @Override
    public Map providersByCountry() {
        return Collections.unmodifiableMap(this.providersByCountry);
    }

    private void initializeResourcesFromInner() {
        this.providersByCountry = new TreeMap<>();
        List availableProvidersList = this.inner().countries();
        if (availableProvidersList != null) {
            for (AvailableProvidersListCountry resource : availableProvidersList) {
                this.providersByCountry.put(resource.countryName(), resource);
            }
        }
    }

    @Override
    public NetworkWatcher parent() {
        return parent;
    }

    @Override
    public AvailableProvidersListInner inner() {
        return this.inner;
    }

    @Override
    public Observable executeWorkAsync() {
        return this.parent().manager().inner().networkWatchers()
                .listAvailableProvidersAsync(parent().resourceGroupName(), parent().name(), parameters)
                .map(new Func1() {
                    @Override
                    public AvailableProviders call(AvailableProvidersListInner availableProvidersListInner) {
                        AvailableProvidersImpl.this.inner = availableProvidersListInner;
                        AvailableProvidersImpl.this.initializeResourcesFromInner();
                        return AvailableProvidersImpl.this;
                    }
                });
    }

    @Override
    public AvailableProvidersImpl withAzureLocations(String... azureLocations) {
        parameters.withAzureLocations(Arrays.asList(azureLocations));
        return this;
    }

    @Override
    public AvailableProvidersImpl withAzureLocation(String azureLocation) {
        if (parameters.azureLocations() == null) {
            parameters.withAzureLocations(new ArrayList());
        }
        parameters.azureLocations().add(azureLocation);
        return this;
    }

    @Override
    public AvailableProvidersImpl withCountry(String country) {
        parameters.withCountry(country);
        return this;
    }

    @Override
    public AvailableProvidersImpl withState(String state) {
        parameters.withState(state);
        return this;
    }

    @Override
    public AvailableProvidersImpl withCity(String city) {
        parameters.withCity(city);
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy