software.amazon.awssdk.services.cloudwatch.model.InsightRuleContributor 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.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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;
/**
*
* One of the unique contributors found by a Contributor Insights rule. If the rule contains multiple keys, then a
* unique contributor is a unique combination of values from all the keys in the rule.
*
*
* If the rule contains a single key, then each unique contributor is each unique value for this key.
*
*
* For more information, see GetInsightRuleReport.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class InsightRuleContributor implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField> KEYS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Keys")
.getter(getter(InsightRuleContributor::keys))
.setter(setter(Builder::keys))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Keys").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField APPROXIMATE_AGGREGATE_VALUE_FIELD = SdkField. builder(MarshallingType.DOUBLE)
.memberName("ApproximateAggregateValue").getter(getter(InsightRuleContributor::approximateAggregateValue))
.setter(setter(Builder::approximateAggregateValue))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ApproximateAggregateValue").build())
.build();
private static final SdkField> DATAPOINTS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Datapoints")
.getter(getter(InsightRuleContributor::datapoints))
.setter(setter(Builder::datapoints))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Datapoints").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(InsightRuleContributorDatapoint::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(KEYS_FIELD,
APPROXIMATE_AGGREGATE_VALUE_FIELD, DATAPOINTS_FIELD));
private static final Map> SDK_NAME_TO_FIELD = Collections
.unmodifiableMap(new HashMap>() {
{
put("Keys", KEYS_FIELD);
put("ApproximateAggregateValue", APPROXIMATE_AGGREGATE_VALUE_FIELD);
put("Datapoints", DATAPOINTS_FIELD);
}
});
private static final long serialVersionUID = 1L;
private final List keys;
private final Double approximateAggregateValue;
private final List datapoints;
private InsightRuleContributor(BuilderImpl builder) {
this.keys = builder.keys;
this.approximateAggregateValue = builder.approximateAggregateValue;
this.datapoints = builder.datapoints;
}
/**
* For responses, this returns true if the service returned a value for the Keys 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 hasKeys() {
return keys != null && !(keys instanceof SdkAutoConstructList);
}
/**
*
* One of the log entry field keywords that is used to define contributors for this rule.
*
*
* 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 #hasKeys} method.
*
*
* @return One of the log entry field keywords that is used to define contributors for this rule.
*/
public final List keys() {
return keys;
}
/**
*
* An approximation of the aggregate value that comes from this contributor.
*
*
* @return An approximation of the aggregate value that comes from this contributor.
*/
public final Double approximateAggregateValue() {
return approximateAggregateValue;
}
/**
* For responses, this returns true if the service returned a value for the Datapoints 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 hasDatapoints() {
return datapoints != null && !(datapoints instanceof SdkAutoConstructList);
}
/**
*
* An array of the data points where this contributor is present. Only the data points when this contributor
* appeared are included in the array.
*
*
* 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 #hasDatapoints} method.
*
*
* @return An array of the data points where this contributor is present. Only the data points when this contributor
* appeared are included in the array.
*/
public final List datapoints() {
return datapoints;
}
@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(hasKeys() ? keys() : null);
hashCode = 31 * hashCode + Objects.hashCode(approximateAggregateValue());
hashCode = 31 * hashCode + Objects.hashCode(hasDatapoints() ? datapoints() : 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 InsightRuleContributor)) {
return false;
}
InsightRuleContributor other = (InsightRuleContributor) obj;
return hasKeys() == other.hasKeys() && Objects.equals(keys(), other.keys())
&& Objects.equals(approximateAggregateValue(), other.approximateAggregateValue())
&& hasDatapoints() == other.hasDatapoints() && Objects.equals(datapoints(), other.datapoints());
}
/**
* 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("InsightRuleContributor").add("Keys", hasKeys() ? keys() : null)
.add("ApproximateAggregateValue", approximateAggregateValue())
.add("Datapoints", hasDatapoints() ? datapoints() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Keys":
return Optional.ofNullable(clazz.cast(keys()));
case "ApproximateAggregateValue":
return Optional.ofNullable(clazz.cast(approximateAggregateValue()));
case "Datapoints":
return Optional.ofNullable(clazz.cast(datapoints()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
@Override
public final Map> sdkFieldNameToField() {
return SDK_NAME_TO_FIELD;
}
private static Function