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

software.amazon.awssdk.services.cloudwatch.model.MetricDatum Maven / Gradle / Ivy

Go to download

A single bundled dependency that includes all service and dependent JARs with third-party libraries relocated to different namespaces.

There is a newer version: 2.5.20
Show newest version
/*
 * 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.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* Encapsulates the information sent to either create a metric or add new values to be aggregated into an existing * metric. *

*/ @Generated("software.amazon.awssdk:codegen") public final class MetricDatum implements ToCopyableBuilder { private final String metricName; private final List dimensions; private final Instant timestamp; private final Double value; private final StatisticSet statisticValues; private final String unit; private final Integer storageResolution; private MetricDatum(BuilderImpl builder) { this.metricName = builder.metricName; this.dimensions = builder.dimensions; this.timestamp = builder.timestamp; this.value = builder.value; this.statisticValues = builder.statisticValues; this.unit = builder.unit; this.storageResolution = builder.storageResolution; } /** *

* The name of the metric. *

* * @return The name of the metric. */ public String metricName() { return metricName; } /** *

* The dimensions associated with the metric. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return The dimensions associated with the metric. */ public List dimensions() { return dimensions; } /** *

* The time the metric data was received, expressed as the number of milliseconds since Jan 1, 1970 00:00:00 UTC. *

* * @return The time the metric data was received, expressed as the number of milliseconds since Jan 1, 1970 00:00:00 * UTC. */ public Instant timestamp() { return timestamp; } /** *

* The value for the metric. *

*

* Although the parameter accepts numbers of type Double, CloudWatch rejects values that are either too small or too * large. Values must be in the range of 8.515920e-109 to 1.174271e+108 (Base 10) or 2e-360 to 2e360 (Base 2). In * addition, special values (for example, NaN, +Infinity, -Infinity) are not supported. *

* * @return The value for the metric.

*

* Although the parameter accepts numbers of type Double, CloudWatch rejects values that are either too * small or too large. Values must be in the range of 8.515920e-109 to 1.174271e+108 (Base 10) or 2e-360 to * 2e360 (Base 2). In addition, special values (for example, NaN, +Infinity, -Infinity) are not supported. */ public Double value() { return value; } /** *

* The statistical values for the metric. *

* * @return The statistical values for the metric. */ public StatisticSet statisticValues() { return statisticValues; } /** *

* The unit of the metric. *

*

* 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 of the metric. * @see StandardUnit */ public StandardUnit unit() { return StandardUnit.fromValue(unit); } /** *

* The unit of the metric. *

*

* 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 of the metric. * @see StandardUnit */ public String unitAsString() { return unit; } /** *

* Valid values are 1 and 60. Setting this to 1 specifies this metric as a high-resolution metric, so that * CloudWatch stores the metric with sub-minute resolution down to one second. Setting this to 60 specifies this * metric as a regular-resolution metric, which CloudWatch stores at 1-minute resolution. Currently, high resolution * is available only for custom metrics. For more information about high-resolution metrics, see High-Resolution Metrics in the Amazon CloudWatch User Guide. *

*

* This field is optional, if you do not specify it the default of 60 is used. *

* * @return Valid values are 1 and 60. Setting this to 1 specifies this metric as a high-resolution metric, so that * CloudWatch stores the metric with sub-minute resolution down to one second. Setting this to 60 specifies * this metric as a regular-resolution metric, which CloudWatch stores at 1-minute resolution. Currently, * high resolution is available only for custom metrics. For more information about high-resolution metrics, * see High-Resolution Metrics in the Amazon CloudWatch User Guide.

*

* This field is optional, if you do not specify it the default of 60 is used. */ public Integer storageResolution() { return storageResolution; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(metricName()); hashCode = 31 * hashCode + Objects.hashCode(dimensions()); hashCode = 31 * hashCode + Objects.hashCode(timestamp()); hashCode = 31 * hashCode + Objects.hashCode(value()); hashCode = 31 * hashCode + Objects.hashCode(statisticValues()); hashCode = 31 * hashCode + Objects.hashCode(unitAsString()); hashCode = 31 * hashCode + Objects.hashCode(storageResolution()); return hashCode; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof MetricDatum)) { return false; } MetricDatum other = (MetricDatum) obj; return Objects.equals(metricName(), other.metricName()) && Objects.equals(dimensions(), other.dimensions()) && Objects.equals(timestamp(), other.timestamp()) && Objects.equals(value(), other.value()) && Objects.equals(statisticValues(), other.statisticValues()) && Objects.equals(unitAsString(), other.unitAsString()) && Objects.equals(storageResolution(), other.storageResolution()); } @Override public String toString() { return ToString.builder("MetricDatum").add("MetricName", metricName()).add("Dimensions", dimensions()) .add("Timestamp", timestamp()).add("Value", value()).add("StatisticValues", statisticValues()) .add("Unit", unitAsString()).add("StorageResolution", storageResolution()).build(); } public Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "MetricName": return Optional.ofNullable(clazz.cast(metricName())); case "Dimensions": return Optional.ofNullable(clazz.cast(dimensions())); case "Timestamp": return Optional.ofNullable(clazz.cast(timestamp())); case "Value": return Optional.ofNullable(clazz.cast(value())); case "StatisticValues": return Optional.ofNullable(clazz.cast(statisticValues())); case "Unit": return Optional.ofNullable(clazz.cast(unitAsString())); case "StorageResolution": return Optional.ofNullable(clazz.cast(storageResolution())); default: return Optional.empty(); } } public interface Builder extends CopyableBuilder { /** *

* The name of the metric. *

* * @param metricName * The name of the metric. * @return Returns a reference to this object so that method calls can be chained together. */ Builder metricName(String metricName); /** *

* The dimensions associated with the metric. *

* * @param dimensions * The dimensions associated with the metric. * @return Returns a reference to this object so that method calls can be chained together. */ Builder dimensions(Collection dimensions); /** *

* The dimensions associated with the metric. *

* * @param dimensions * The dimensions associated with the metric. * @return Returns a reference to this object so that method calls can be chained together. */ Builder dimensions(Dimension... dimensions); /** *

* The dimensions associated with the metric. *

* This is a convenience that creates an instance of the {@link List.Builder} avoiding the need to * create one manually via {@link List#builder()}. * * When the {@link Consumer} completes, {@link List.Builder#build()} is called immediately and its * result is passed to {@link #dimensions(List)}. * * @param dimensions * a consumer that will call methods on {@link List.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #dimensions(List) */ Builder dimensions(Consumer... dimensions); /** *

* The time the metric data was received, expressed as the number of milliseconds since Jan 1, 1970 00:00:00 * UTC. *

* * @param timestamp * The time the metric data was received, expressed as the number of milliseconds since Jan 1, 1970 * 00:00:00 UTC. * @return Returns a reference to this object so that method calls can be chained together. */ Builder timestamp(Instant timestamp); /** *

* The value for the metric. *

*

* Although the parameter accepts numbers of type Double, CloudWatch rejects values that are either too small or * too large. Values must be in the range of 8.515920e-109 to 1.174271e+108 (Base 10) or 2e-360 to 2e360 (Base * 2). In addition, special values (for example, NaN, +Infinity, -Infinity) are not supported. *

* * @param value * The value for the metric.

*

* Although the parameter accepts numbers of type Double, CloudWatch rejects values that are either too * small or too large. Values must be in the range of 8.515920e-109 to 1.174271e+108 (Base 10) or 2e-360 * to 2e360 (Base 2). In addition, special values (for example, NaN, +Infinity, -Infinity) are not * supported. * @return Returns a reference to this object so that method calls can be chained together. */ Builder value(Double value); /** *

* The statistical values for the metric. *

* * @param statisticValues * The statistical values for the metric. * @return Returns a reference to this object so that method calls can be chained together. */ Builder statisticValues(StatisticSet statisticValues); /** *

* The statistical values for the metric. *

* This is a convenience that creates an instance of the {@link StatisticSet.Builder} avoiding the need to * create one manually via {@link StatisticSet#builder()}. * * When the {@link Consumer} completes, {@link StatisticSet.Builder#build()} is called immediately and its * result is passed to {@link #statisticValues(StatisticSet)}. * * @param statisticValues * a consumer that will call methods on {@link StatisticSet.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #statisticValues(StatisticSet) */ default Builder statisticValues(Consumer statisticValues) { return statisticValues(StatisticSet.builder().applyMutation(statisticValues).build()); } /** *

* The unit of the metric. *

* * @param unit * The unit of the metric. * @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 of the metric. *

* * @param unit * The unit of the metric. * @see StandardUnit * @return Returns a reference to this object so that method calls can be chained together. * @see StandardUnit */ Builder unit(StandardUnit unit); /** *

* Valid values are 1 and 60. Setting this to 1 specifies this metric as a high-resolution metric, so that * CloudWatch stores the metric with sub-minute resolution down to one second. Setting this to 60 specifies this * metric as a regular-resolution metric, which CloudWatch stores at 1-minute resolution. Currently, high * resolution is available only for custom metrics. For more information about high-resolution metrics, see High-Resolution Metrics in the Amazon CloudWatch User Guide. *

*

* This field is optional, if you do not specify it the default of 60 is used. *

* * @param storageResolution * Valid values are 1 and 60. Setting this to 1 specifies this metric as a high-resolution metric, so * that CloudWatch stores the metric with sub-minute resolution down to one second. Setting this to 60 * specifies this metric as a regular-resolution metric, which CloudWatch stores at 1-minute resolution. * Currently, high resolution is available only for custom metrics. For more information about * high-resolution metrics, see High-Resolution Metrics in the Amazon CloudWatch User Guide.

*

* This field is optional, if you do not specify it the default of 60 is used. * @return Returns a reference to this object so that method calls can be chained together. */ Builder storageResolution(Integer storageResolution); } static final class BuilderImpl implements Builder { private String metricName; private List dimensions = DefaultSdkAutoConstructList.getInstance(); private Instant timestamp; private Double value; private StatisticSet statisticValues; private String unit; private Integer storageResolution; private BuilderImpl() { } private BuilderImpl(MetricDatum model) { metricName(model.metricName); dimensions(model.dimensions); timestamp(model.timestamp); value(model.value); statisticValues(model.statisticValues); unit(model.unit); storageResolution(model.storageResolution); } public final String getMetricName() { return metricName; } @Override public final Builder metricName(String metricName) { this.metricName = metricName; return this; } public final void setMetricName(String metricName) { this.metricName = metricName; } public final Collection getDimensions() { return dimensions != null ? dimensions.stream().map(Dimension::toBuilder).collect(Collectors.toList()) : null; } @Override public final Builder dimensions(Collection dimensions) { this.dimensions = DimensionsCopier.copy(dimensions); return this; } @Override @SafeVarargs public final Builder dimensions(Dimension... dimensions) { dimensions(Arrays.asList(dimensions)); return this; } @Override @SafeVarargs public final Builder dimensions(Consumer... dimensions) { dimensions(Stream.of(dimensions).map(c -> Dimension.builder().applyMutation(c).build()).collect(Collectors.toList())); return this; } public final void setDimensions(Collection dimensions) { this.dimensions = DimensionsCopier.copyFromBuilder(dimensions); } 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 getValue() { return value; } @Override public final Builder value(Double value) { this.value = value; return this; } public final void setValue(Double value) { this.value = value; } public final StatisticSet.Builder getStatisticValues() { return statisticValues != null ? statisticValues.toBuilder() : null; } @Override public final Builder statisticValues(StatisticSet statisticValues) { this.statisticValues = statisticValues; return this; } public final void setStatisticValues(StatisticSet.BuilderImpl statisticValues) { this.statisticValues = statisticValues != null ? statisticValues.build() : null; } 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 Integer getStorageResolution() { return storageResolution; } @Override public final Builder storageResolution(Integer storageResolution) { this.storageResolution = storageResolution; return this; } public final void setStorageResolution(Integer storageResolution) { this.storageResolution = storageResolution; } @Override public MetricDatum build() { return new MetricDatum(this); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy