Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.hengyi.japp.execution.domain; import com.google.common.collect.Sets; import com.hengyi.japp.execution.data.SendStatus; import java.util.Arrays; import java.util.Date; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.Lob; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import static org.apache.commons.lang3.StringUtils.deleteWhitespace; import org.hibernate.validator.constraints.NotBlank; /** * * @author jzb */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @Entity @Table(name = "T_SMS") public class Sms extends AbstractEntity implements Comparable<Sms> { private static final long serialVersionUID = 1L; @NotNull @ManyToOne @JoinColumn(nullable = false) private Customer customer; @NotBlank @Lob @Column(nullable = false) private String content; @NotNull @Size(min = 1) @ManyToMany private Set<Mobile> mobiles; @NotNull @Temporal(TemporalType.TIMESTAMP) @Column(nullable = false) private Date sendDateTime; @NotNull @Column(nullable = false) private SendStatus status = SendStatus.INIT; @Column(name = "sendResult") private String result; public boolean isSuccess() { return SendStatus.SUCCESS.equals(status); } public String getPhonesAsString() { Set<String> phoneSet = Sets.newHashSet(); for (Mobile mobile : getMobiles()) { phoneSet.add(mobile.getPhone()); } String phones = Arrays.toString(phoneSet.toArray()); phones = deleteWhitespace(phones); return phones.substring(1, phones.length() - 1); } public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public Set<Mobile> getMobiles() { return mobiles; } public void setMobiles(Set<Mobile> mobiles) { this.mobiles = mobiles; } public Date getSendDateTime() { return sendDateTime; } public void setSendDateTime(Date sendDateTime) { this.sendDateTime = sendDateTime; } public SendStatus getStatus() { return status; } public void setStatus(SendStatus status) { this.status = status; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } @Override public int compareTo(Sms o) { if (getSendDateTime() == null || o.getSendDateTime() == null) { return 0; } return getSendDateTime().compareTo(o.getSendDateTime()); } }