Fortune.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package hello.home.entity;
  2. import com.techempower.data.annotation.*;
  3. import com.techempower.js.*;
  4. /**
  5. * A fortune entity.
  6. */
  7. @Entity
  8. public class Fortune
  9. extends GhDataEntity
  10. implements Comparable<Fortune>
  11. {
  12. private String message;
  13. /**
  14. * Default Constructor.
  15. */
  16. public Fortune()
  17. {
  18. // Does nothing.
  19. }
  20. /**
  21. * Set the message.
  22. */
  23. public Fortune setMessage(String message)
  24. {
  25. this.message = message;
  26. return this;
  27. }
  28. /**
  29. * Get the message.
  30. */
  31. public String getMessage()
  32. {
  33. return this.message;
  34. }
  35. /**
  36. * A visitor factory used to map this class to JSON.
  37. */
  38. public static final VisitorFactory<Fortune> VISITOR_FACTORY = new VisitorFactory<Fortune>()
  39. {
  40. @Override
  41. public Visitor visitor(Fortune fortune)
  42. {
  43. return Visitors.map(
  44. "id", fortune.getId(),
  45. "message", fortune.getMessage());
  46. }
  47. };
  48. /**
  49. * For our purposes, Fortunes sort by their message text.
  50. */
  51. @Override
  52. public int compareTo(Fortune other)
  53. {
  54. return getMessage().compareTo(other.getMessage());
  55. }
  56. }