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.

ClonePart.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.duplications.index;
  21. public class ClonePart {
  22. private final String resourceId;
  23. private final int startUnit;
  24. private final int startLine;
  25. private final int endLine;
  26. /**
  27. * Cache for hash code.
  28. */
  29. private int hash;
  30. public ClonePart(String resourceId, int startUnit, int startLine, int endLine) {
  31. this.resourceId = resourceId;
  32. this.startUnit = startUnit;
  33. this.startLine = startLine;
  34. this.endLine = endLine;
  35. }
  36. public String getResourceId() {
  37. return resourceId;
  38. }
  39. public int getUnitStart() {
  40. return startUnit;
  41. }
  42. public int getStartLine() {
  43. return startLine;
  44. }
  45. public int getEndLine() {
  46. return endLine;
  47. }
  48. public int getLines() {
  49. return endLine - startLine + 1;
  50. }
  51. @Override
  52. public boolean equals(Object obj) {
  53. if (obj instanceof ClonePart) {
  54. ClonePart another = (ClonePart) obj;
  55. return another.resourceId.equals(resourceId)
  56. && another.startLine == startLine
  57. && another.endLine == endLine
  58. && another.startUnit == startUnit;
  59. }
  60. return false;
  61. }
  62. @Override
  63. public int hashCode() {
  64. int h = hash;
  65. if (h == 0) {
  66. h = resourceId.hashCode();
  67. h = 31 * h + startLine;
  68. h = 31 * h + endLine;
  69. h = 31 * h + startUnit;
  70. hash = h;
  71. }
  72. return h;
  73. }
  74. @Override
  75. public String toString() {
  76. return "'" + resourceId + "':[" + startUnit + "|" + startLine + "-" + endLine + "]";
  77. }
  78. }