Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package com.kdstudio.snippets.tips.apache;
  2.  
  3. import org.apache.commons.lang3.builder.EqualsBuilder;
  4. import org.apache.commons.lang3.builder.HashCodeBuilder;
  5. import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
  6. import org.apache.commons.lang3.builder.ToStringStyle;
  7.  
  8. /**
  9. * Example of using Commons-lang3 utilities.
  10. *
  11. * Lang provides a host of helper utilities for the java.lang API, notably
  12. * String manipulation methods, basic numerical methods, object reflection,
  13. * concurrency, creation and serialization and System properties. Additionally
  14. * it contains basic enhancements to java.util.Date and a series of utilities
  15. * dedicated to help with building methods, such as hashCode, toString and
  16. * equals.
  17. *
  18. * @author kdelfour
  19. */
  20. public class HashCodeEqualsToStringExample {
  21.  
  22. /**
  23. * Constructor
  24. */
  25. public HashCodeEqualsToStringExample() {
  26. }
  27.  
  28. /*
  29. * (non-Javadoc)
  30. *
  31. * @see java.lang.Object#toString()
  32. */
  33. @Override
  34. public String toString() {
  35. return ReflectionToStringBuilder.toString(this,
  36. ToStringStyle.MULTI_LINE_STYLE);
  37. }
  38.  
  39. /*
  40. * (non-Javadoc)
  41. *
  42. * @see java.lang.Object#hashCode()
  43. */
  44. @Override
  45. public int hashCode() {
  46. return HashCodeBuilder.reflectionHashCode(this);
  47. }
  48.  
  49. /*
  50. * (non-Javadoc)
  51. *
  52. * @see java.lang.Object#equals(java.lang.Object)
  53. */
  54. @Override
  55. public boolean equals(Object obj) {
  56. return EqualsBuilder.reflectionEquals(this, obj);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement