Паттерн: Цепочка обязанностей (Chain of Responsibility)
Исходник: News.java, язык: java [code #483, hits: 6361]
автор: this [добавлен: 04.10.2007]
  1. package chainOfResponsibility;
  2.  
  3. import java.util.Date;
  4.  
  5. public class News {
  6. private String title;
  7. private Date date;
  8. private String txt;
  9.  
  10. public News(String title, Date date, String txt) {
  11. super();
  12. this.title = title;
  13. this.date = date;
  14. this.txt = txt;
  15. }
  16.  
  17. public Date getDate() {
  18. return date;
  19. }
  20.  
  21. public String getTitle() {
  22. return title;
  23. }
  24.  
  25. public String getTxt() {
  26. return txt;
  27. }
  28.  
  29. public int hashCode() {
  30. final int PRIME = 31;
  31. int result = 1;
  32. result = PRIME * result + ((date == null) ? 0 : date.hashCode());
  33. result = PRIME * result + ((title == null) ? 0 : title.hashCode());
  34. result = PRIME * result + ((txt == null) ? 0 : txt.hashCode());
  35. return result;
  36. }
  37.  
  38. public boolean equals(Object obj) {
  39. if (this == obj)
  40. return true;
  41. if (!(obj instanceof News)) {
  42. return false;
  43. }
  44.  
  45. final News other = (News) obj;
  46. if (date == null) {
  47. if (other.date != null)
  48. return false;
  49. } else if (!date.equals(other.date))
  50. return false;
  51. if (title == null) {
  52. if (other.title != null)
  53. return false;
  54. } else if (!title.equals(other.title))
  55. return false;
  56. if (txt == null) {
  57. if (other.txt != null)
  58. return false;
  59. } else if (!txt.equals(other.txt))
  60. return false;
  61. return true;
  62. }
  63.  
  64.  
  65. }
Просто модель сущности "Новость"
Тестировалось на: java 1.5.0_04

+добавить реализацию