
com.azure.resourcemanager.network.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.network.fluent.models;
import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import com.azure.resourcemanager.network.models.UsageName;
import com.azure.resourcemanager.network.models.UsageUnit;
import java.io.IOException;
/**
* The network resource usage.
*/
@Fluent
public final class UsageInner implements JsonSerializable {
/*
* Resource identifier.
*/
private String id;
/*
* An enum describing the unit of measurement.
*/
private UsageUnit unit;
/*
* The current value of the usage.
*/
private long currentValue;
/*
* The limit of usage.
*/
private long limit;
/*
* The name of the type of usage.
*/
private UsageName name;
/**
* Creates an instance of UsageInner class.
*/
public UsageInner() {
}
/**
* Get the id property: Resource identifier.
*
* @return the id value.
*/
public String id() {
return this.id;
}
/**
* Get the unit property: An enum describing the unit of measurement.
*
* @return the unit value.
*/
public UsageUnit unit() {
return this.unit;
}
/**
* Set the unit property: An enum describing the unit of measurement.
*
* @param unit the unit value to set.
* @return the UsageInner object itself.
*/
public UsageInner withUnit(UsageUnit unit) {
this.unit = unit;
return this;
}
/**
* Get the currentValue property: The current value of the usage.
*
* @return the currentValue value.
*/
public long currentValue() {
return this.currentValue;
}
/**
* Set the currentValue property: The current value of the usage.
*
* @param currentValue the currentValue value to set.
* @return the UsageInner object itself.
*/
public UsageInner withCurrentValue(long currentValue) {
this.currentValue = currentValue;
return this;
}
/**
* Get the limit property: The limit of usage.
*
* @return the limit value.
*/
public long limit() {
return this.limit;
}
/**
* Set the limit property: The limit of usage.
*
* @param limit the limit value to set.
* @return the UsageInner object itself.
*/
public UsageInner withLimit(long limit) {
this.limit = limit;
return this;
}
/**
* Get the name property: The name of the type of usage.
*
* @return the name value.
*/
public UsageName name() {
return this.name;
}
/**
* Set the name property: The name of the type of usage.
*
* @param name the name value to set.
* @return the UsageInner object itself.
*/
public UsageInner withName(UsageName name) {
this.name = name;
return this;
}
/**
* Validates the instance.
*
* @throws IllegalArgumentException thrown if the instance is not valid.
*/
public void validate() {
if (unit() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException("Missing required property unit in model UsageInner"));
}
if (name() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException("Missing required property name in model UsageInner"));
} else {
name().validate();
}
}
private static final ClientLogger LOGGER = new ClientLogger(UsageInner.class);
/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("unit", this.unit == null ? null : this.unit.toString());
jsonWriter.writeLongField("currentValue", this.currentValue);
jsonWriter.writeLongField("limit", this.limit);
jsonWriter.writeJsonField("name", this.name);
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 IllegalStateException If the deserialized JSON object was missing any required properties.
* @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 ("unit".equals(fieldName)) {
deserializedUsageInner.unit = UsageUnit.fromString(reader.getString());
} else if ("currentValue".equals(fieldName)) {
deserializedUsageInner.currentValue = reader.getLong();
} else if ("limit".equals(fieldName)) {
deserializedUsageInner.limit = reader.getLong();
} else if ("name".equals(fieldName)) {
deserializedUsageInner.name = UsageName.fromJson(reader);
} else if ("id".equals(fieldName)) {
deserializedUsageInner.id = reader.getString();
} else {
reader.skipChildren();
}
}
return deserializedUsageInner;
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy