software.amazon.awssdk.services.pinpoint.model.SimpleEmail Maven / Gradle / Ivy
Show all versions of pinpoint 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.pinpoint.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;
/**
*
* Specifies the contents of an email message, composed of a subject, a text part, and an HTML part.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class SimpleEmail implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField HTML_PART_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("HtmlPart").getter(getter(SimpleEmail::htmlPart)).setter(setter(Builder::htmlPart))
.constructor(SimpleEmailPart::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("HtmlPart").build()).build();
private static final SdkField SUBJECT_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("Subject").getter(getter(SimpleEmail::subject)).setter(setter(Builder::subject))
.constructor(SimpleEmailPart::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Subject").build()).build();
private static final SdkField TEXT_PART_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("TextPart").getter(getter(SimpleEmail::textPart)).setter(setter(Builder::textPart))
.constructor(SimpleEmailPart::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TextPart").build()).build();
private static final SdkField> HEADERS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Headers")
.getter(getter(SimpleEmail::headers))
.setter(setter(Builder::headers))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Headers").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(MessageHeader::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(HTML_PART_FIELD,
SUBJECT_FIELD, TEXT_PART_FIELD, HEADERS_FIELD));
private static final Map> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
private static final long serialVersionUID = 1L;
private final SimpleEmailPart htmlPart;
private final SimpleEmailPart subject;
private final SimpleEmailPart textPart;
private final List headers;
private SimpleEmail(BuilderImpl builder) {
this.htmlPart = builder.htmlPart;
this.subject = builder.subject;
this.textPart = builder.textPart;
this.headers = builder.headers;
}
/**
*
* The body of the email message, in HTML format. We recommend using HTML format for email clients that render HTML
* content. You can include links, formatted text, and more in an HTML message.
*
*
* @return The body of the email message, in HTML format. We recommend using HTML format for email clients that
* render HTML content. You can include links, formatted text, and more in an HTML message.
*/
public final SimpleEmailPart htmlPart() {
return htmlPart;
}
/**
*
* The subject line, or title, of the email.
*
*
* @return The subject line, or title, of the email.
*/
public final SimpleEmailPart subject() {
return subject;
}
/**
*
* The body of the email message, in plain text format. We recommend using plain text format for email clients that
* don't render HTML content and clients that are connected to high-latency networks, such as mobile devices.
*
*
* @return The body of the email message, in plain text format. We recommend using plain text format for email
* clients that don't render HTML content and clients that are connected to high-latency networks, such as
* mobile devices.
*/
public final SimpleEmailPart textPart() {
return textPart;
}
/**
* For responses, this returns true if the service returned a value for the Headers 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 hasHeaders() {
return headers != null && !(headers instanceof SdkAutoConstructList);
}
/**
*
* The list of MessageHeaders for the email. You can have up to 15 Headers.
*
*
* 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 #hasHeaders} method.
*
*
* @return The list of MessageHeaders for the email. You can have up to 15 Headers.
*/
public final List headers() {
return headers;
}
@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(htmlPart());
hashCode = 31 * hashCode + Objects.hashCode(subject());
hashCode = 31 * hashCode + Objects.hashCode(textPart());
hashCode = 31 * hashCode + Objects.hashCode(hasHeaders() ? headers() : 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 SimpleEmail)) {
return false;
}
SimpleEmail other = (SimpleEmail) obj;
return Objects.equals(htmlPart(), other.htmlPart()) && Objects.equals(subject(), other.subject())
&& Objects.equals(textPart(), other.textPart()) && hasHeaders() == other.hasHeaders()
&& Objects.equals(headers(), other.headers());
}
/**
* 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("SimpleEmail").add("HtmlPart", htmlPart()).add("Subject", subject()).add("TextPart", textPart())
.add("Headers", hasHeaders() ? headers() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "HtmlPart":
return Optional.ofNullable(clazz.cast(htmlPart()));
case "Subject":
return Optional.ofNullable(clazz.cast(subject()));
case "TextPart":
return Optional.ofNullable(clazz.cast(textPart()));
case "Headers":
return Optional.ofNullable(clazz.cast(headers()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
@Override
public final Map> sdkFieldNameToField() {
return SDK_NAME_TO_FIELD;
}
private static Map> memberNameToFieldInitializer() {
Map> map = new HashMap<>();
map.put("HtmlPart", HTML_PART_FIELD);
map.put("Subject", SUBJECT_FIELD);
map.put("TextPart", TEXT_PART_FIELD);
map.put("Headers", HEADERS_FIELD);
return Collections.unmodifiableMap(map);
}
private static Function