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.

AbstractMatcher.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2014, Andrey Loskutov <loskutov@gmx.de> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.ignore.internal;
  11. import org.eclipse.jgit.ignore.IMatcher;
  12. /**
  13. * Base class for default methods as {@link #toString()} and such.
  14. * <p>
  15. * This class is immutable and thread safe.
  16. */
  17. public abstract class AbstractMatcher implements IMatcher {
  18. final boolean dirOnly;
  19. final String pattern;
  20. /**
  21. * @param pattern
  22. * string to parse
  23. * @param dirOnly
  24. * true if this matcher should match only directories
  25. */
  26. AbstractMatcher(String pattern, boolean dirOnly) {
  27. this.pattern = pattern;
  28. this.dirOnly = dirOnly;
  29. }
  30. /** {@inheritDoc} */
  31. @Override
  32. public String toString() {
  33. return pattern;
  34. }
  35. /** {@inheritDoc} */
  36. @Override
  37. public int hashCode() {
  38. return pattern.hashCode();
  39. }
  40. /** {@inheritDoc} */
  41. @Override
  42. public boolean equals(Object obj) {
  43. if (this == obj)
  44. return true;
  45. if (!(obj instanceof AbstractMatcher))
  46. return false;
  47. AbstractMatcher other = (AbstractMatcher) obj;
  48. return dirOnly == other.dirOnly && pattern.equals(other.pattern);
  49. }
  50. }