You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RowId.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.sqlcontainer;
  5. import java.io.Serializable;
  6. /**
  7. * RowId represents identifiers of a single database result set row.
  8. *
  9. * The data structure of a RowId is an Object array which contains the values of
  10. * the primary key columns of the identified row. This allows easy equals()
  11. * -comparison of RowItems.
  12. */
  13. public class RowId implements Serializable {
  14. private static final long serialVersionUID = -3161778404698901258L;
  15. protected Object[] id;
  16. /**
  17. * Prevent instantiation without required parameters.
  18. */
  19. protected RowId() {
  20. }
  21. public RowId(Object[] id) {
  22. if (id == null) {
  23. throw new IllegalArgumentException("id parameter must not be null!");
  24. }
  25. this.id = id;
  26. }
  27. public Object[] getId() {
  28. return id;
  29. }
  30. @Override
  31. public int hashCode() {
  32. int result = 31;
  33. if (id != null) {
  34. for (Object o : id) {
  35. if (o != null) {
  36. result += o.hashCode();
  37. }
  38. }
  39. }
  40. return result;
  41. }
  42. @Override
  43. public boolean equals(Object obj) {
  44. if (obj == null || !(obj instanceof RowId)) {
  45. return false;
  46. }
  47. Object[] compId = ((RowId) obj).getId();
  48. if (id == null && compId == null) {
  49. return true;
  50. }
  51. if (id.length != compId.length) {
  52. return false;
  53. }
  54. for (int i = 0; i < id.length; i++) {
  55. if ((id[i] == null && compId[i] != null)
  56. || (id[i] != null && !id[i].equals(compId[i]))) {
  57. return false;
  58. }
  59. }
  60. return true;
  61. }
  62. @Override
  63. public String toString() {
  64. StringBuffer s = new StringBuffer();
  65. for (int i = 0; i < id.length; i++) {
  66. s.append(id[i]);
  67. if (i < id.length - 1) {
  68. s.append("/");
  69. }
  70. }
  71. return s.toString();
  72. }
  73. }