|
| 1 | +package org.koushik.javabrains.messenger.model; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Date; |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Map; |
| 8 | + |
| 9 | +import javax.xml.bind.annotation.XmlRootElement; |
| 10 | +import javax.xml.bind.annotation.XmlTransient; |
| 11 | + |
| 12 | + |
| 13 | +@XmlRootElement |
| 14 | +public class Message { |
| 15 | + |
| 16 | + private long id; |
| 17 | + private String message; |
| 18 | + private Date created; |
| 19 | + private String author; |
| 20 | + private Map<Long, Comment> comments = new HashMap<>(); |
| 21 | + private List<Link> links = new ArrayList<>(); |
| 22 | + |
| 23 | + public Message() { |
| 24 | + |
| 25 | + } |
| 26 | + |
| 27 | + public Message(long id, String message, String author) { |
| 28 | + this.id = id; |
| 29 | + this.message = message; |
| 30 | + this.author = author; |
| 31 | + this.created = new Date(); |
| 32 | + } |
| 33 | + |
| 34 | + public long getId() { |
| 35 | + return id; |
| 36 | + } |
| 37 | + |
| 38 | + public void setId(long id) { |
| 39 | + this.id = id; |
| 40 | + } |
| 41 | + |
| 42 | + public String getMessage() { |
| 43 | + return message; |
| 44 | + } |
| 45 | + |
| 46 | + public void setMessage(String message) { |
| 47 | + this.message = message; |
| 48 | + } |
| 49 | + |
| 50 | + public Date getCreated() { |
| 51 | + return created; |
| 52 | + } |
| 53 | + |
| 54 | + public void setCreated(Date created) { |
| 55 | + this.created = created; |
| 56 | + } |
| 57 | + |
| 58 | + public String getAuthor() { |
| 59 | + return author; |
| 60 | + } |
| 61 | + |
| 62 | + public void setAuthor(String author) { |
| 63 | + this.author = author; |
| 64 | + } |
| 65 | + |
| 66 | + @XmlTransient |
| 67 | + public Map<Long, Comment> getComments() { |
| 68 | + return comments; |
| 69 | + } |
| 70 | + |
| 71 | + public void setComments(Map<Long, Comment> comments) { |
| 72 | + this.comments = comments; |
| 73 | + } |
| 74 | + |
| 75 | + public List<Link> getLinks() { |
| 76 | + return links; |
| 77 | + } |
| 78 | + |
| 79 | + public void setLinks(List<Link> links) { |
| 80 | + this.links = links; |
| 81 | + } |
| 82 | + |
| 83 | + public void addLink(String url, String rel) { |
| 84 | + Link link = new Link(); |
| 85 | + link.setLink(url); |
| 86 | + link.setRel(rel); |
| 87 | + links.add(link); |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments