Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. package pt.uc.dei.proj3.common;
  2.  
  3. import java.io.Serializable;
  4. import java.util.GregorianCalendar;
  5.  
  6. import javax.xml.bind.annotation.XmlRootElement;
  7.  
  8. /**
  9. * POJO mensagem, que contem um rementente data de envio e conteudo.
  10. * Nota: As mensagens sรณ "existem" associadas a um chat
  11. */
  12. @XmlRootElement
  13. public class Mensagem implements Serializable{
  14.  
  15. /**
  16. *
  17. */
  18. private static final long serialVersionUID = -3570514059296199504L;
  19.  
  20. private static int idGerado;
  21. private int id;
  22. private Utilizador remetente;
  23. private GregorianCalendar dataEnvio;
  24. private String texto;
  25.  
  26. /****CONSTRUTORES****/
  27. public Mensagem() {}
  28.  
  29. public Mensagem(Utilizador remetente, String texto) {
  30. idGerado++;
  31. this.id=idGerado;
  32. this.remetente=remetente;
  33. this.dataEnvio=new GregorianCalendar();
  34. this.texto=texto;
  35. }
  36.  
  37. public Mensagem(int id, Utilizador remetente, GregorianCalendar dataEnvio, String texto) {
  38. this.id=id;
  39. this.remetente=remetente;
  40. this.dataEnvio=dataEnvio;
  41. this.texto=texto;
  42.  
  43. if (idGerado < id) {
  44. idGerado=id;
  45. }
  46. }
  47.  
  48. /****METODOS PUBLICOS****/
  49. /**
  50. * Devolve a hora de envio da mensagem com o formato hh:mm
  51. * @return String com a hora da mensagem
  52. */
  53. public String horaMensagem() {
  54. return String.format("%tR", dataEnvio);
  55. }
  56.  
  57. /**
  58. * Devolve o dia de envio da mensagem com o formato yyyy-mm-dd
  59. * @return String com o dia da mensagem
  60. */
  61. public String diaMensagem() {
  62. return String.format("%tF", dataEnvio);
  63. }
  64.  
  65. /****GETTERS E SETTERS****/
  66. /**
  67. * @return the idGerado
  68. */
  69. public static int getIdGerado() {
  70. return idGerado;
  71. }
  72.  
  73. /**
  74. * @param idGerado the idGerado to set
  75. */
  76. public static void setIdGerado(int idGerado) {
  77. Mensagem.idGerado = idGerado;
  78. }
  79.  
  80. /**
  81. * @return the id
  82. */
  83. public int getId() {
  84. return id;
  85. }
  86.  
  87. /**
  88. * @param id the id to set
  89. */
  90. public void setId(int id) {
  91. this.id = id;
  92. }
  93.  
  94. /**
  95. * @return the remetente
  96. */
  97. public Utilizador getRemetente() {
  98. return remetente;
  99. }
  100.  
  101. /**
  102. * @param remetente the remetente to set
  103. */
  104. public void setRemetente(Utilizador remetente) {
  105. this.remetente = remetente;
  106. }
  107.  
  108. /**
  109. * @return the dataEnvio
  110. */
  111. public GregorianCalendar getDataEnvio() {
  112. return dataEnvio;
  113. }
  114.  
  115. /**
  116. * @param dataEnvio the dataEnvio to set
  117. */
  118. public void setDataEnvio(GregorianCalendar dataEnvio) {
  119. this.dataEnvio = dataEnvio;
  120. }
  121.  
  122. /**
  123. * @return the texto
  124. */
  125. public String getTexto() {
  126. return texto;
  127. }
  128.  
  129. /**
  130. * @param texto the texto to set
  131. */
  132. public void setTexto(String texto) {
  133. this.texto = texto;
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement