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

com.sendgrid.helpers.mail.objects.Personalization Maven / Gradle / Ivy

Go to download

This Java module allows you to quickly and easily send emails through Twilio SendGrid using Java.

There is a newer version: 5.0.0-rc.1
Show newest version
package com.sendgrid.helpers.mail.objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@JsonInclude(Include.NON_DEFAULT)
public class Personalization {

  @JsonProperty("to")
  private List tos;

  @JsonProperty("cc")
  private List ccs;

  @JsonProperty("bcc")
  private List bccs;

  @JsonProperty("subject")
  private String subject;

  @JsonProperty("headers")
  private Map headers;

  @JsonProperty("substitutions")
  private Map substitutions;

  @JsonProperty("custom_args")
  private Map customArgs;

  @JsonProperty("dynamic_template_data")
  private Map dynamicTemplateData;

  @JsonProperty("send_at")
  private long sendAt;

  @JsonProperty("to")
  public List getTos() {
    if (tos == null) {
      return Collections.emptyList();
    }
    return tos;
  }

  public void addTo(Email email) {
    Email newEmail = new Email();
    newEmail.setName(email.getName());
    newEmail.setEmail(email.getEmail());
    if (tos == null) {
      tos = new ArrayList();
      tos.add(newEmail);
    } else {
      tos.add(newEmail);
    }
  }

  @JsonProperty("cc")
  public List getCcs() {
    if (ccs == null) {
      return Collections.emptyList();
    }
    return ccs;
  }

  public void addCc(Email email) {
    Email newEmail = new Email();
    newEmail.setName(email.getName());
    newEmail.setEmail(email.getEmail());
    if (ccs == null) {
      ccs = new ArrayList();
      ccs.add(newEmail);
    } else {
      ccs.add(newEmail);
    }
  }

  @JsonProperty("bcc")
  public List getBccs() {
    if (bccs == null) {
      return Collections.emptyList();
    }
    return bccs;
  }

  public void addBcc(Email email) {
    Email newEmail = new Email();
    newEmail.setName(email.getName());
    newEmail.setEmail(email.getEmail());
    if (bccs == null) {
      bccs = new ArrayList();
      bccs.add(newEmail);
    } else {
      bccs.add(newEmail);
    }
  }

  @JsonProperty("subject")
  public String getSubject() {
    return subject;
  }

  public void setSubject(String subject) {
    this.subject = subject;
  }

  @JsonProperty("headers")
  public Map getHeaders() {
    if (headers == null) {
      return Collections.emptyMap();
    }
    return headers;
  }

  public void addHeader(String key, String value) {
    if (headers == null) {
      headers = new HashMap();
      headers.put(key, value);
    } else {
      headers.put(key, value);
    }
  }

  @JsonProperty("substitutions")
  public Map getSubstitutions() {
    if (substitutions == null) {
      return Collections.emptyMap();
    }
    return substitutions;
  }

  public void addSubstitution(String key, String value) {
    if (substitutions == null) {
      substitutions = new HashMap();
      substitutions.put(key, value);
    } else {
      substitutions.put(key, value);
    }
  }

  @JsonProperty("custom_args")
  public Map getCustomArgs() {
    if (customArgs == null) {
      return Collections.emptyMap();
    }
    return customArgs;
  }

  public void addCustomArg(String key, String value) {
    if (customArgs == null) {
      customArgs = new HashMap();
      customArgs.put(key, value);
    } else {
      customArgs.put(key, value);
    }
  }

  @JsonProperty("send_at")
  public long sendAt() {
    return sendAt;
  }

  public void setSendAt(long sendAt) {
    this.sendAt = sendAt;
  }

  @JsonProperty("dynamic_template_data")
  public Map getDynamicTemplateData() {
    return dynamicTemplateData == null
        ? Collections.emptyMap() : dynamicTemplateData;
  }

  public void addDynamicTemplateData(String key, Object value) {
    if (dynamicTemplateData == null) {
      dynamicTemplateData = new HashMap();
    }
    dynamicTemplateData.put(key, value);
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((bccs == null) ? 0 : bccs.hashCode());
    result = prime * result + ((ccs == null) ? 0 : ccs.hashCode());
    result = prime * result + ((customArgs == null) ? 0 : customArgs.hashCode());
    result = prime * result + ((headers == null) ? 0 : headers.hashCode());
    result = prime * result + (int) (sendAt ^ (sendAt >>> 32));
    result = prime * result + ((subject == null) ? 0 : subject.hashCode());
    result = prime * result + ((substitutions == null) ? 0 : substitutions.hashCode());
    result = prime * result + ((tos == null) ? 0 : tos.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    Personalization other = (Personalization) obj;
    if (bccs == null) {
      if (other.bccs != null) {
        return false;
      }
    } else if (!bccs.equals(other.bccs)) {
      return false;
    }
    if (ccs == null) {
      if (other.ccs != null) {
        return false;
      }
    } else if (!ccs.equals(other.ccs)) {
      return false;
    }
    if (customArgs == null) {
      if (other.customArgs != null) {
        return false;
      }
    } else if (!customArgs.equals(other.customArgs)) {
      return false;
    }
    if (headers == null) {
      if (other.headers != null) {
        return false;
      }
    } else if (!headers.equals(other.headers)) {
      return false;
    }
    if (sendAt != other.sendAt) {
      return false;
    }
    if (subject == null) {
      if (other.subject != null) {
        return false;
      }
    } else if (!subject.equals(other.subject)) {
      return false;
    }
    if (substitutions == null) {
      if (other.substitutions != null) {
        return false;
      }
    } else if (!substitutions.equals(other.substitutions)) {
      return false;
    }
    if (tos == null) {
      if (other.tos != null) {
        return false;
      }
    } else if (!tos.equals(other.tos)) {
      return false;
    }
    return true;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy