Class AbstractFuzzyMatcher<T>

java.lang.Object
com.comphenix.protocol.reflect.fuzzy.AbstractFuzzyMatcher<T>
All Implemented Interfaces:
Comparable<AbstractFuzzyMatcher<T>>
Direct Known Subclasses:
AbstractFuzzyMember, FuzzyClassContract

public abstract class AbstractFuzzyMatcher<T> extends Object implements Comparable<AbstractFuzzyMatcher<T>>
Represents a matcher for fields, methods, constructors and classes.

This class should ideally never expose mutable state. Its round number must be immutable.

Author:
Kristian
  • Constructor Details

    • AbstractFuzzyMatcher

      public AbstractFuzzyMatcher()
  • Method Details

    • isMatch

      public abstract boolean isMatch(T value, Object parent)
      Determine if the given value is a match.
      Parameters:
      value - - the value to match.
      parent - - the parent container, or NULL if this value is the root.
      Returns:
      TRUE if it is a match, FALSE otherwise.
    • calculateRoundNumber

      protected abstract int calculateRoundNumber()
      Calculate the round number indicating when this matcher should be applied.

      Matchers with a lower round number are applied before matchers with a higher round number.

      By convention, this round number should be negative, except for zero in the case of a matcher that accepts any value. A good implementation should return the inverted tree depth (class hierachy) of the least specified type used in the matching. Thus Integer will have a lower round number than Number.

      Returns:
      A number (positive or negative) that is used to order matchers.
    • getRoundNumber

      public final int getRoundNumber()
      Retrieve the cached round number. This should never change once calculated.

      Matchers with a lower round number are applied before matchers with a higher round number.

      Returns:
      The round number.
      See Also:
      calculateRoundNumber()
    • combineRounds

      protected final int combineRounds(int roundA, int roundB)
      Combine two round numbers by taking the highest non-zero number, or return zero.
      Parameters:
      roundA - - the first round number.
      roundB - - the second round number.
      Returns:
      The combined round number.
    • combineRounds

      protected final int combineRounds(Integer... rounds)
      Combine n round numbers by taking the highest non-zero number, or return zero.
      Parameters:
      rounds - - the round numbers.
      Returns:
      The combined round number.
    • compareTo

      public int compareTo(AbstractFuzzyMatcher<T> obj)
      Specified by:
      compareTo in interface Comparable<T>
    • inverted

      public AbstractFuzzyMatcher<T> inverted()
      Create a fuzzy matcher that returns the opposite result of the current matcher.
      Returns:
      An inverted fuzzy matcher.
    • and

      public AbstractFuzzyMatcher<T> and(AbstractFuzzyMatcher<T> other)
      Require that this and the given matcher be TRUE.
      Parameters:
      other - - the other fuzzy matcher.
      Returns:
      A combined fuzzy matcher.
    • or

      public AbstractFuzzyMatcher<T> or(AbstractFuzzyMatcher<T> other)
      Require that either this or the other given matcher be TRUE.
      Parameters:
      other - - the other fuzzy matcher.
      Returns:
      A combined fuzzy matcher.