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

com.azure.resourcemanager.automation.fluent.models.UsageInner Maven / Gradle / Ivy

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

package com.azure.resourcemanager.automation.fluent.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 com.azure.resourcemanager.automation.models.UsageCounterName;
import java.io.IOException;

/**
 * Definition of Usage.
 */
@Fluent
public final class UsageInner implements JsonSerializable {
    /*
     * Gets or sets the id of the resource.
     */
    private String id;

    /*
     * Gets or sets the usage counter name.
     */
    private UsageCounterName name;

    /*
     * Gets or sets the usage unit name.
     */
    private String unit;

    /*
     * Gets or sets the current usage value.
     */
    private Double currentValue;

    /*
     * Gets or sets max limit. -1 for unlimited
     */
    private Long limit;

    /*
     * Gets or sets the throttle status.
     */
    private String throttleStatus;

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

    /**
     * Get the id property: Gets or sets the id of the resource.
     * 
     * @return the id value.
     */
    public String id() {
        return this.id;
    }

    /**
     * Set the id property: Gets or sets the id of the resource.
     * 
     * @param id the id value to set.
     * @return the UsageInner object itself.
     */
    public UsageInner withId(String id) {
        this.id = id;
        return this;
    }

    /**
     * Get the name property: Gets or sets the usage counter name.
     * 
     * @return the name value.
     */
    public UsageCounterName name() {
        return this.name;
    }

    /**
     * Set the name property: Gets or sets the usage counter name.
     * 
     * @param name the name value to set.
     * @return the UsageInner object itself.
     */
    public UsageInner withName(UsageCounterName name) {
        this.name = name;
        return this;
    }

    /**
     * Get the unit property: Gets or sets the usage unit name.
     * 
     * @return the unit value.
     */
    public String unit() {
        return this.unit;
    }

    /**
     * Set the unit property: Gets or sets the usage unit name.
     * 
     * @param unit the unit value to set.
     * @return the UsageInner object itself.
     */
    public UsageInner withUnit(String unit) {
        this.unit = unit;
        return this;
    }

    /**
     * Get the currentValue property: Gets or sets the current usage value.
     * 
     * @return the currentValue value.
     */
    public Double currentValue() {
        return this.currentValue;
    }

    /**
     * Set the currentValue property: Gets or sets the current usage value.
     * 
     * @param currentValue the currentValue value to set.
     * @return the UsageInner object itself.
     */
    public UsageInner withCurrentValue(Double currentValue) {
        this.currentValue = currentValue;
        return this;
    }

    /**
     * Get the limit property: Gets or sets max limit. -1 for unlimited.
     * 
     * @return the limit value.
     */
    public Long limit() {
        return this.limit;
    }

    /**
     * Set the limit property: Gets or sets max limit. -1 for unlimited.
     * 
     * @param limit the limit value to set.
     * @return the UsageInner object itself.
     */
    public UsageInner withLimit(Long limit) {
        this.limit = limit;
        return this;
    }

    /**
     * Get the throttleStatus property: Gets or sets the throttle status.
     * 
     * @return the throttleStatus value.
     */
    public String throttleStatus() {
        return this.throttleStatus;
    }

    /**
     * Set the throttleStatus property: Gets or sets the throttle status.
     * 
     * @param throttleStatus the throttleStatus value to set.
     * @return the UsageInner object itself.
     */
    public UsageInner withThrottleStatus(String throttleStatus) {
        this.throttleStatus = throttleStatus;
        return this;
    }

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("id", this.id);
        jsonWriter.writeJsonField("name", this.name);
        jsonWriter.writeStringField("unit", this.unit);
        jsonWriter.writeNumberField("currentValue", this.currentValue);
        jsonWriter.writeNumberField("limit", this.limit);
        jsonWriter.writeStringField("throttleStatus", this.throttleStatus);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of UsageInner from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of UsageInner 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 UsageInner.
     */
    public static UsageInner fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            UsageInner deserializedUsageInner = new UsageInner();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("id".equals(fieldName)) {
                    deserializedUsageInner.id = reader.getString();
                } else if ("name".equals(fieldName)) {
                    deserializedUsageInner.name = UsageCounterName.fromJson(reader);
                } else if ("unit".equals(fieldName)) {
                    deserializedUsageInner.unit = reader.getString();
                } else if ("currentValue".equals(fieldName)) {
                    deserializedUsageInner.currentValue = reader.getNullable(JsonReader::getDouble);
                } else if ("limit".equals(fieldName)) {
                    deserializedUsageInner.limit = reader.getNullable(JsonReader::getLong);
                } else if ("throttleStatus".equals(fieldName)) {
                    deserializedUsageInner.throttleStatus = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedUsageInner;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy