
software.amazon.awssdk.services.cloudwatch.model.MetricStat Maven / Gradle / Ivy
/*
* Copyright 2013-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.cloudwatch.model;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* This structure defines the metric to be returned, along with the statistics, period, and units.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class MetricStat implements ToCopyableBuilder {
private final Metric metric;
private final Integer period;
private final String stat;
private final String unit;
private MetricStat(BuilderImpl builder) {
this.metric = builder.metric;
this.period = builder.period;
this.stat = builder.stat;
this.unit = builder.unit;
}
/**
*
* The metric to return, including the metric name, namespace, and dimensions.
*
*
* @return The metric to return, including the metric name, namespace, and dimensions.
*/
public Metric metric() {
return metric;
}
/**
*
* The period to use when retrieving the metric.
*
*
* @return The period to use when retrieving the metric.
*/
public Integer period() {
return period;
}
/**
*
* The statistic to return. It can include any CloudWatch statistic or extended statistic.
*
*
* @return The statistic to return. It can include any CloudWatch statistic or extended statistic.
*/
public String stat() {
return stat;
}
/**
*
* The unit to use for the returned data points.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #unit} will return
* {@link StandardUnit#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #unitAsString}.
*
*
* @return The unit to use for the returned data points.
* @see StandardUnit
*/
public StandardUnit unit() {
return StandardUnit.fromValue(unit);
}
/**
*
* The unit to use for the returned data points.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #unit} will return
* {@link StandardUnit#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #unitAsString}.
*
*
* @return The unit to use for the returned data points.
* @see StandardUnit
*/
public String unitAsString() {
return unit;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(metric());
hashCode = 31 * hashCode + Objects.hashCode(period());
hashCode = 31 * hashCode + Objects.hashCode(stat());
hashCode = 31 * hashCode + Objects.hashCode(unitAsString());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof MetricStat)) {
return false;
}
MetricStat other = (MetricStat) obj;
return Objects.equals(metric(), other.metric()) && Objects.equals(period(), other.period())
&& Objects.equals(stat(), other.stat()) && Objects.equals(unitAsString(), other.unitAsString());
}
@Override
public String toString() {
return ToString.builder("MetricStat").add("Metric", metric()).add("Period", period()).add("Stat", stat())
.add("Unit", unitAsString()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Metric":
return Optional.ofNullable(clazz.cast(metric()));
case "Period":
return Optional.ofNullable(clazz.cast(period()));
case "Stat":
return Optional.ofNullable(clazz.cast(stat()));
case "Unit":
return Optional.ofNullable(clazz.cast(unitAsString()));
default:
return Optional.empty();
}
}
public interface Builder extends CopyableBuilder {
/**
*
* The metric to return, including the metric name, namespace, and dimensions.
*
*
* @param metric
* The metric to return, including the metric name, namespace, and dimensions.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder metric(Metric metric);
/**
*
* The metric to return, including the metric name, namespace, and dimensions.
*
* This is a convenience that creates an instance of the {@link Metric.Builder} avoiding the need to create one
* manually via {@link Metric#builder()}.
*
* When the {@link Consumer} completes, {@link Metric.Builder#build()} is called immediately and its result is
* passed to {@link #metric(Metric)}.
*
* @param metric
* a consumer that will call methods on {@link Metric.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #metric(Metric)
*/
default Builder metric(Consumer metric) {
return metric(Metric.builder().applyMutation(metric).build());
}
/**
*
* The period to use when retrieving the metric.
*
*
* @param period
* The period to use when retrieving the metric.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder period(Integer period);
/**
*
* The statistic to return. It can include any CloudWatch statistic or extended statistic.
*
*
* @param stat
* The statistic to return. It can include any CloudWatch statistic or extended statistic.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder stat(String stat);
/**
*
* The unit to use for the returned data points.
*
*
* @param unit
* The unit to use for the returned data points.
* @see StandardUnit
* @return Returns a reference to this object so that method calls can be chained together.
* @see StandardUnit
*/
Builder unit(String unit);
/**
*
* The unit to use for the returned data points.
*
*
* @param unit
* The unit to use for the returned data points.
* @see StandardUnit
* @return Returns a reference to this object so that method calls can be chained together.
* @see StandardUnit
*/
Builder unit(StandardUnit unit);
}
static final class BuilderImpl implements Builder {
private Metric metric;
private Integer period;
private String stat;
private String unit;
private BuilderImpl() {
}
private BuilderImpl(MetricStat model) {
metric(model.metric);
period(model.period);
stat(model.stat);
unit(model.unit);
}
public final Metric.Builder getMetric() {
return metric != null ? metric.toBuilder() : null;
}
@Override
public final Builder metric(Metric metric) {
this.metric = metric;
return this;
}
public final void setMetric(Metric.BuilderImpl metric) {
this.metric = metric != null ? metric.build() : null;
}
public final Integer getPeriod() {
return period;
}
@Override
public final Builder period(Integer period) {
this.period = period;
return this;
}
public final void setPeriod(Integer period) {
this.period = period;
}
public final String getStat() {
return stat;
}
@Override
public final Builder stat(String stat) {
this.stat = stat;
return this;
}
public final void setStat(String stat) {
this.stat = stat;
}
public final String getUnit() {
return unit;
}
@Override
public final Builder unit(String unit) {
this.unit = unit;
return this;
}
@Override
public final Builder unit(StandardUnit unit) {
this.unit(unit.toString());
return this;
}
public final void setUnit(String unit) {
this.unit = unit;
}
@Override
public MetricStat build() {
return new MetricStat(this);
}
}
}