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.

Link.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.util.text;
  18. import java.util.Objects;
  19. /**
  20. * Describes a single link found within some text.
  21. */
  22. public class Link {
  23. private final int start;
  24. private final int end;
  25. private final String content;
  26. public Link(final int start, final int end, final String content) {
  27. this.start = start;
  28. this.end = end;
  29. this.content = content;
  30. }
  31. /**
  32. * Gets the character offset that the link was found at.
  33. *
  34. * @return The position the link was found at
  35. */
  36. public int getStart() {
  37. return start;
  38. }
  39. /**
  40. * Gets the character offset of the end of the link.
  41. *
  42. * @return The position immediately after the last character of the link.
  43. */
  44. public int getEnd() {
  45. return end;
  46. }
  47. /**
  48. * Gets the content of the link.
  49. *
  50. * @return The link's content
  51. */
  52. public String getContent() {
  53. return content;
  54. }
  55. @Override
  56. public boolean equals(final Object o) {
  57. if (o instanceof Link) {
  58. final Link link = (Link) o;
  59. return end == link.getEnd()
  60. && start == link.getStart()
  61. && Objects.equals(content, link.getContent());
  62. }
  63. return false;
  64. }
  65. @Override
  66. public int hashCode() {
  67. return Objects.hash(start, end, content);
  68. }
  69. @Override
  70. public String toString() {
  71. return "Link{start=" + start + ", end=" + end + ", content='" + content + "'}";
  72. }
  73. }