
software.amazon.awssdk.services.cloudwatch.model.Datapoint 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.time.Instant;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Encapsulates the statistical data that CloudWatch computes from metric data.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class Datapoint implements ToCopyableBuilder {
private final Instant timestamp;
private final Double sampleCount;
private final Double average;
private final Double sum;
private final Double minimum;
private final Double maximum;
private final String unit;
private final Map extendedStatistics;
private Datapoint(BuilderImpl builder) {
this.timestamp = builder.timestamp;
this.sampleCount = builder.sampleCount;
this.average = builder.average;
this.sum = builder.sum;
this.minimum = builder.minimum;
this.maximum = builder.maximum;
this.unit = builder.unit;
this.extendedStatistics = builder.extendedStatistics;
}
/**
*
* The time stamp used for the data point.
*
*
* @return The time stamp used for the data point.
*/
public Instant timestamp() {
return timestamp;
}
/**
*
* The number of metric values that contributed to the aggregate value of this data point.
*
*
* @return The number of metric values that contributed to the aggregate value of this data point.
*/
public Double sampleCount() {
return sampleCount;
}
/**
*
* The average of the metric values that correspond to the data point.
*
*
* @return The average of the metric values that correspond to the data point.
*/
public Double average() {
return average;
}
/**
*
* The sum of the metric values for the data point.
*
*
* @return The sum of the metric values for the data point.
*/
public Double sum() {
return sum;
}
/**
*
* The minimum metric value for the data point.
*
*
* @return The minimum metric value for the data point.
*/
public Double minimum() {
return minimum;
}
/**
*
* The maximum metric value for the data point.
*
*
* @return The maximum metric value for the data point.
*/
public Double maximum() {
return maximum;
}
/**
*
* The standard unit for the data point.
*
*
* 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 standard unit for the data point.
* @see StandardUnit
*/
public StandardUnit unit() {
return StandardUnit.fromValue(unit);
}
/**
*
* The standard unit for the data point.
*
*
* 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 standard unit for the data point.
* @see StandardUnit
*/
public String unitAsString() {
return unit;
}
/**
*
* The percentile statistic for the data point.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return The percentile statistic for the data point.
*/
public Map extendedStatistics() {
return extendedStatistics;
}
@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(timestamp());
hashCode = 31 * hashCode + Objects.hashCode(sampleCount());
hashCode = 31 * hashCode + Objects.hashCode(average());
hashCode = 31 * hashCode + Objects.hashCode(sum());
hashCode = 31 * hashCode + Objects.hashCode(minimum());
hashCode = 31 * hashCode + Objects.hashCode(maximum());
hashCode = 31 * hashCode + Objects.hashCode(unitAsString());
hashCode = 31 * hashCode + Objects.hashCode(extendedStatistics());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Datapoint)) {
return false;
}
Datapoint other = (Datapoint) obj;
return Objects.equals(timestamp(), other.timestamp()) && Objects.equals(sampleCount(), other.sampleCount())
&& Objects.equals(average(), other.average()) && Objects.equals(sum(), other.sum())
&& Objects.equals(minimum(), other.minimum()) && Objects.equals(maximum(), other.maximum())
&& Objects.equals(unitAsString(), other.unitAsString())
&& Objects.equals(extendedStatistics(), other.extendedStatistics());
}
@Override
public String toString() {
return ToString.builder("Datapoint").add("Timestamp", timestamp()).add("SampleCount", sampleCount())
.add("Average", average()).add("Sum", sum()).add("Minimum", minimum()).add("Maximum", maximum())
.add("Unit", unitAsString()).add("ExtendedStatistics", extendedStatistics()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Timestamp":
return Optional.ofNullable(clazz.cast(timestamp()));
case "SampleCount":
return Optional.ofNullable(clazz.cast(sampleCount()));
case "Average":
return Optional.ofNullable(clazz.cast(average()));
case "Sum":
return Optional.ofNullable(clazz.cast(sum()));
case "Minimum":
return Optional.ofNullable(clazz.cast(minimum()));
case "Maximum":
return Optional.ofNullable(clazz.cast(maximum()));
case "Unit":
return Optional.ofNullable(clazz.cast(unitAsString()));
case "ExtendedStatistics":
return Optional.ofNullable(clazz.cast(extendedStatistics()));
default:
return Optional.empty();
}
}
public interface Builder extends CopyableBuilder {
/**
*
* The time stamp used for the data point.
*
*
* @param timestamp
* The time stamp used for the data point.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder timestamp(Instant timestamp);
/**
*
* The number of metric values that contributed to the aggregate value of this data point.
*
*
* @param sampleCount
* The number of metric values that contributed to the aggregate value of this data point.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder sampleCount(Double sampleCount);
/**
*
* The average of the metric values that correspond to the data point.
*
*
* @param average
* The average of the metric values that correspond to the data point.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder average(Double average);
/**
*
* The sum of the metric values for the data point.
*
*
* @param sum
* The sum of the metric values for the data point.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder sum(Double sum);
/**
*
* The minimum metric value for the data point.
*
*
* @param minimum
* The minimum metric value for the data point.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder minimum(Double minimum);
/**
*
* The maximum metric value for the data point.
*
*
* @param maximum
* The maximum metric value for the data point.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder maximum(Double maximum);
/**
*
* The standard unit for the data point.
*
*
* @param unit
* The standard unit for the data point.
* @see StandardUnit
* @return Returns a reference to this object so that method calls can be chained together.
* @see StandardUnit
*/
Builder unit(String unit);
/**
*
* The standard unit for the data point.
*
*
* @param unit
* The standard unit for the data point.
* @see StandardUnit
* @return Returns a reference to this object so that method calls can be chained together.
* @see StandardUnit
*/
Builder unit(StandardUnit unit);
/**
*
* The percentile statistic for the data point.
*
*
* @param extendedStatistics
* The percentile statistic for the data point.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder extendedStatistics(Map extendedStatistics);
}
static final class BuilderImpl implements Builder {
private Instant timestamp;
private Double sampleCount;
private Double average;
private Double sum;
private Double minimum;
private Double maximum;
private String unit;
private Map extendedStatistics = DefaultSdkAutoConstructMap.getInstance();
private BuilderImpl() {
}
private BuilderImpl(Datapoint model) {
timestamp(model.timestamp);
sampleCount(model.sampleCount);
average(model.average);
sum(model.sum);
minimum(model.minimum);
maximum(model.maximum);
unit(model.unit);
extendedStatistics(model.extendedStatistics);
}
public final Instant getTimestamp() {
return timestamp;
}
@Override
public final Builder timestamp(Instant timestamp) {
this.timestamp = timestamp;
return this;
}
public final void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}
public final Double getSampleCount() {
return sampleCount;
}
@Override
public final Builder sampleCount(Double sampleCount) {
this.sampleCount = sampleCount;
return this;
}
public final void setSampleCount(Double sampleCount) {
this.sampleCount = sampleCount;
}
public final Double getAverage() {
return average;
}
@Override
public final Builder average(Double average) {
this.average = average;
return this;
}
public final void setAverage(Double average) {
this.average = average;
}
public final Double getSum() {
return sum;
}
@Override
public final Builder sum(Double sum) {
this.sum = sum;
return this;
}
public final void setSum(Double sum) {
this.sum = sum;
}
public final Double getMinimum() {
return minimum;
}
@Override
public final Builder minimum(Double minimum) {
this.minimum = minimum;
return this;
}
public final void setMinimum(Double minimum) {
this.minimum = minimum;
}
public final Double getMaximum() {
return maximum;
}
@Override
public final Builder maximum(Double maximum) {
this.maximum = maximum;
return this;
}
public final void setMaximum(Double maximum) {
this.maximum = maximum;
}
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;
}
public final Map getExtendedStatistics() {
return extendedStatistics;
}
@Override
public final Builder extendedStatistics(Map extendedStatistics) {
this.extendedStatistics = DatapointValueMapCopier.copy(extendedStatistics);
return this;
}
public final void setExtendedStatistics(Map extendedStatistics) {
this.extendedStatistics = DatapointValueMapCopier.copy(extendedStatistics);
}
@Override
public Datapoint build() {
return new Datapoint(this);
}
}
}