software.amazon.awssdk.services.cloudwatch.model.MetricDataResult Maven / Gradle / Ivy
Show all versions of cloudwatch Show documentation
/*
* Copyright 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.io.Serializable;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* A GetMetricData
call returns an array of MetricDataResult
structures. Each of these
* structures includes the data points for that metric, along with the timestamps of those data points and other
* identifying information.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class MetricDataResult implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField ID_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Id")
.getter(getter(MetricDataResult::id)).setter(setter(Builder::id))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Id").build()).build();
private static final SdkField LABEL_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Label")
.getter(getter(MetricDataResult::label)).setter(setter(Builder::label))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Label").build()).build();
private static final SdkField> TIMESTAMPS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Timestamps")
.getter(getter(MetricDataResult::timestamps))
.setter(setter(Builder::timestamps))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Timestamps").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.INSTANT)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> VALUES_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Values")
.getter(getter(MetricDataResult::values))
.setter(setter(Builder::values))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Values").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.DOUBLE)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField STATUS_CODE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("StatusCode").getter(getter(MetricDataResult::statusCodeAsString)).setter(setter(Builder::statusCode))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("StatusCode").build()).build();
private static final SdkField> MESSAGES_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Messages")
.getter(getter(MetricDataResult::messages))
.setter(setter(Builder::messages))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Messages").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(MessageData::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(ID_FIELD, LABEL_FIELD,
TIMESTAMPS_FIELD, VALUES_FIELD, STATUS_CODE_FIELD, MESSAGES_FIELD));
private static final long serialVersionUID = 1L;
private final String id;
private final String label;
private final List timestamps;
private final List values;
private final String statusCode;
private final List messages;
private MetricDataResult(BuilderImpl builder) {
this.id = builder.id;
this.label = builder.label;
this.timestamps = builder.timestamps;
this.values = builder.values;
this.statusCode = builder.statusCode;
this.messages = builder.messages;
}
/**
*
* The short name you specified to represent this metric.
*
*
* @return The short name you specified to represent this metric.
*/
public final String id() {
return id;
}
/**
*
* The human-readable label associated with the data.
*
*
* @return The human-readable label associated with the data.
*/
public final String label() {
return label;
}
/**
* For responses, this returns true if the service returned a value for the Timestamps property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasTimestamps() {
return timestamps != null && !(timestamps instanceof SdkAutoConstructList);
}
/**
*
* The timestamps for the data points, formatted in Unix timestamp format. The number of timestamps always matches
* the number of values and the value for Timestamps[x] is Values[x].
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasTimestamps} method.
*
*
* @return The timestamps for the data points, formatted in Unix timestamp format. The number of timestamps always
* matches the number of values and the value for Timestamps[x] is Values[x].
*/
public final List timestamps() {
return timestamps;
}
/**
* For responses, this returns true if the service returned a value for the Values property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasValues() {
return values != null && !(values instanceof SdkAutoConstructList);
}
/**
*
* The data points for the metric corresponding to Timestamps
. The number of values always matches the
* number of timestamps and the timestamp for Values[x] is Timestamps[x].
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasValues} method.
*
*
* @return The data points for the metric corresponding to Timestamps
. The number of values always
* matches the number of timestamps and the timestamp for Values[x] is Timestamps[x].
*/
public final List values() {
return values;
}
/**
*
* The status of the returned data. Complete
indicates that all data points in the requested time range
* were returned. PartialData
means that an incomplete set of data points were returned. You can use
* the NextToken
value that was returned and repeat your request to get more data points.
* NextToken
is not returned if you are performing a math expression. InternalError
* indicates that an error occurred. Retry your request using NextToken
, if present.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #statusCode} will
* return {@link StatusCode#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #statusCodeAsString}.
*
*
* @return The status of the returned data. Complete
indicates that all data points in the requested
* time range were returned. PartialData
means that an incomplete set of data points were
* returned. You can use the NextToken
value that was returned and repeat your request to get
* more data points. NextToken
is not returned if you are performing a math expression.
* InternalError
indicates that an error occurred. Retry your request using
* NextToken
, if present.
* @see StatusCode
*/
public final StatusCode statusCode() {
return StatusCode.fromValue(statusCode);
}
/**
*
* The status of the returned data. Complete
indicates that all data points in the requested time range
* were returned. PartialData
means that an incomplete set of data points were returned. You can use
* the NextToken
value that was returned and repeat your request to get more data points.
* NextToken
is not returned if you are performing a math expression. InternalError
* indicates that an error occurred. Retry your request using NextToken
, if present.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #statusCode} will
* return {@link StatusCode#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #statusCodeAsString}.
*
*
* @return The status of the returned data. Complete
indicates that all data points in the requested
* time range were returned. PartialData
means that an incomplete set of data points were
* returned. You can use the NextToken
value that was returned and repeat your request to get
* more data points. NextToken
is not returned if you are performing a math expression.
* InternalError
indicates that an error occurred. Retry your request using
* NextToken
, if present.
* @see StatusCode
*/
public final String statusCodeAsString() {
return statusCode;
}
/**
* For responses, this returns true if the service returned a value for the Messages property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasMessages() {
return messages != null && !(messages instanceof SdkAutoConstructList);
}
/**
*
* A list of messages with additional information about the data returned.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasMessages} method.
*
*
* @return A list of messages with additional information about the data returned.
*/
public final List messages() {
return messages;
}
@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 final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(id());
hashCode = 31 * hashCode + Objects.hashCode(label());
hashCode = 31 * hashCode + Objects.hashCode(hasTimestamps() ? timestamps() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasValues() ? values() : null);
hashCode = 31 * hashCode + Objects.hashCode(statusCodeAsString());
hashCode = 31 * hashCode + Objects.hashCode(hasMessages() ? messages() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof MetricDataResult)) {
return false;
}
MetricDataResult other = (MetricDataResult) obj;
return Objects.equals(id(), other.id()) && Objects.equals(label(), other.label())
&& hasTimestamps() == other.hasTimestamps() && Objects.equals(timestamps(), other.timestamps())
&& hasValues() == other.hasValues() && Objects.equals(values(), other.values())
&& Objects.equals(statusCodeAsString(), other.statusCodeAsString()) && hasMessages() == other.hasMessages()
&& Objects.equals(messages(), other.messages());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("MetricDataResult").add("Id", id()).add("Label", label())
.add("Timestamps", hasTimestamps() ? timestamps() : null).add("Values", hasValues() ? values() : null)
.add("StatusCode", statusCodeAsString()).add("Messages", hasMessages() ? messages() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Id":
return Optional.ofNullable(clazz.cast(id()));
case "Label":
return Optional.ofNullable(clazz.cast(label()));
case "Timestamps":
return Optional.ofNullable(clazz.cast(timestamps()));
case "Values":
return Optional.ofNullable(clazz.cast(values()));
case "StatusCode":
return Optional.ofNullable(clazz.cast(statusCodeAsString()));
case "Messages":
return Optional.ofNullable(clazz.cast(messages()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function