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

com.azure.resourcemanager.avs.models.PlacementPolicyProperties Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure SDK for Avs Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. Azure VMware Solution API. Package tag package-2023-09-01.

The newest version!
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.avs.models;

import com.azure.core.annotation.Fluent;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
 * Abstract placement policy properties.
 */
@Fluent
public class PlacementPolicyProperties implements JsonSerializable {
    /*
     * Placement Policy type
     */
    private PlacementPolicyType type = PlacementPolicyType.fromString("PlacementPolicyProperties");

    /*
     * Whether the placement policy is enabled or disabled
     */
    private PlacementPolicyState state;

    /*
     * Display name of the placement policy
     */
    private String displayName;

    /*
     * The provisioning state
     */
    private PlacementPolicyProvisioningState provisioningState;

    /**
     * Creates an instance of PlacementPolicyProperties class.
     */
    public PlacementPolicyProperties() {
    }

    /**
     * Get the type property: Placement Policy type.
     * 
     * @return the type value.
     */
    public PlacementPolicyType type() {
        return this.type;
    }

    /**
     * Get the state property: Whether the placement policy is enabled or disabled.
     * 
     * @return the state value.
     */
    public PlacementPolicyState state() {
        return this.state;
    }

    /**
     * Set the state property: Whether the placement policy is enabled or disabled.
     * 
     * @param state the state value to set.
     * @return the PlacementPolicyProperties object itself.
     */
    public PlacementPolicyProperties withState(PlacementPolicyState state) {
        this.state = state;
        return this;
    }

    /**
     * Get the displayName property: Display name of the placement policy.
     * 
     * @return the displayName value.
     */
    public String displayName() {
        return this.displayName;
    }

    /**
     * Set the displayName property: Display name of the placement policy.
     * 
     * @param displayName the displayName value to set.
     * @return the PlacementPolicyProperties object itself.
     */
    public PlacementPolicyProperties withDisplayName(String displayName) {
        this.displayName = displayName;
        return this;
    }

    /**
     * Get the provisioningState property: The provisioning state.
     * 
     * @return the provisioningState value.
     */
    public PlacementPolicyProvisioningState provisioningState() {
        return this.provisioningState;
    }

    /**
     * Set the provisioningState property: The provisioning state.
     * 
     * @param provisioningState the provisioningState value to set.
     * @return the PlacementPolicyProperties object itself.
     */
    PlacementPolicyProperties withProvisioningState(PlacementPolicyProvisioningState provisioningState) {
        this.provisioningState = provisioningState;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString());
        jsonWriter.writeStringField("state", this.state == null ? null : this.state.toString());
        jsonWriter.writeStringField("displayName", this.displayName);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of PlacementPolicyProperties from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of PlacementPolicyProperties if the JsonReader was pointing to an instance of it, or null if
     * it was pointing to JSON null.
     * @throws IOException If an error occurs while reading the PlacementPolicyProperties.
     */
    public static PlacementPolicyProperties fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String discriminatorValue = null;
            try (JsonReader readerToUse = reader.bufferObject()) {
                readerToUse.nextToken(); // Prepare for reading
                while (readerToUse.nextToken() != JsonToken.END_OBJECT) {
                    String fieldName = readerToUse.getFieldName();
                    readerToUse.nextToken();
                    if ("type".equals(fieldName)) {
                        discriminatorValue = readerToUse.getString();
                        break;
                    } else {
                        readerToUse.skipChildren();
                    }
                }
                // Use the discriminator value to determine which subtype should be deserialized.
                if ("VmHost".equals(discriminatorValue)) {
                    return VmHostPlacementPolicyProperties.fromJson(readerToUse.reset());
                } else if ("VmVm".equals(discriminatorValue)) {
                    return VmPlacementPolicyProperties.fromJson(readerToUse.reset());
                } else {
                    return fromJsonKnownDiscriminator(readerToUse.reset());
                }
            }
        });
    }

    static PlacementPolicyProperties fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            PlacementPolicyProperties deserializedPlacementPolicyProperties = new PlacementPolicyProperties();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("type".equals(fieldName)) {
                    deserializedPlacementPolicyProperties.type = PlacementPolicyType.fromString(reader.getString());
                } else if ("state".equals(fieldName)) {
                    deserializedPlacementPolicyProperties.state = PlacementPolicyState.fromString(reader.getString());
                } else if ("displayName".equals(fieldName)) {
                    deserializedPlacementPolicyProperties.displayName = reader.getString();
                } else if ("provisioningState".equals(fieldName)) {
                    deserializedPlacementPolicyProperties.provisioningState
                        = PlacementPolicyProvisioningState.fromString(reader.getString());
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedPlacementPolicyProperties;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy