
software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest 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.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.awscore.AwsRequestOverrideConfiguration;
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;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class PutMetricDataRequest extends CloudWatchRequest implements
ToCopyableBuilder {
private final String namespace;
private final List metricData;
private PutMetricDataRequest(BuilderImpl builder) {
super(builder);
this.namespace = builder.namespace;
this.metricData = builder.metricData;
}
/**
*
* The namespace for the metric data.
*
*
* You cannot specify a namespace that begins with "AWS/". Namespaces that begin with "AWS/" are reserved for use by
* Amazon Web Services products.
*
*
* @return The namespace for the metric data.
*
* You cannot specify a namespace that begins with "AWS/". Namespaces that begin with "AWS/" are reserved
* for use by Amazon Web Services products.
*/
public String namespace() {
return namespace;
}
/**
*
* The data for the metric.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return The data for the metric.
*/
public List metricData() {
return metricData;
}
@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(namespace());
hashCode = 31 * hashCode + Objects.hashCode(metricData());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof PutMetricDataRequest)) {
return false;
}
PutMetricDataRequest other = (PutMetricDataRequest) obj;
return Objects.equals(namespace(), other.namespace()) && Objects.equals(metricData(), other.metricData());
}
@Override
public String toString() {
return ToString.builder("PutMetricDataRequest").add("Namespace", namespace()).add("MetricData", metricData()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Namespace":
return Optional.ofNullable(clazz.cast(namespace()));
case "MetricData":
return Optional.ofNullable(clazz.cast(metricData()));
default:
return Optional.empty();
}
}
public interface Builder extends CloudWatchRequest.Builder, CopyableBuilder {
/**
*
* The namespace for the metric data.
*
*
* You cannot specify a namespace that begins with "AWS/". Namespaces that begin with "AWS/" are reserved for
* use by Amazon Web Services products.
*
*
* @param namespace
* The namespace for the metric data.
*
* You cannot specify a namespace that begins with "AWS/". Namespaces that begin with "AWS/" are reserved
* for use by Amazon Web Services products.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder namespace(String namespace);
/**
*
* The data for the metric.
*
*
* @param metricData
* The data for the metric.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder metricData(Collection metricData);
/**
*
* The data for the metric.
*
*
* @param metricData
* The data for the metric.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder metricData(MetricDatum... metricData);
/**
*
* The data for 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 #metricData(List)}.
*
* @param metricData
* 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 #metricData(List)
*/
Builder metricData(Consumer... metricData);
@Override
Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration);
@Override
Builder overrideConfiguration(Consumer builderConsumer);
}
static final class BuilderImpl extends CloudWatchRequest.BuilderImpl implements Builder {
private String namespace;
private List metricData = DefaultSdkAutoConstructList.getInstance();
private BuilderImpl() {
}
private BuilderImpl(PutMetricDataRequest model) {
super(model);
namespace(model.namespace);
metricData(model.metricData);
}
public final String getNamespace() {
return namespace;
}
@Override
public final Builder namespace(String namespace) {
this.namespace = namespace;
return this;
}
public final void setNamespace(String namespace) {
this.namespace = namespace;
}
public final Collection getMetricData() {
return metricData != null ? metricData.stream().map(MetricDatum::toBuilder).collect(Collectors.toList()) : null;
}
@Override
public final Builder metricData(Collection metricData) {
this.metricData = MetricDataCopier.copy(metricData);
return this;
}
@Override
@SafeVarargs
public final Builder metricData(MetricDatum... metricData) {
metricData(Arrays.asList(metricData));
return this;
}
@Override
@SafeVarargs
public final Builder metricData(Consumer... metricData) {
metricData(Stream.of(metricData).map(c -> MetricDatum.builder().applyMutation(c).build())
.collect(Collectors.toList()));
return this;
}
public final void setMetricData(Collection metricData) {
this.metricData = MetricDataCopier.copyFromBuilder(metricData);
}
@Override
public Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration) {
super.overrideConfiguration(overrideConfiguration);
return this;
}
@Override
public Builder overrideConfiguration(Consumer builderConsumer) {
super.overrideConfiguration(builderConsumer);
return this;
}
@Override
public PutMetricDataRequest build() {
return new PutMetricDataRequest(this);
}
}
}