Class UserAgentStringMatchMaker

java.lang.Object
nl.basjes.parse.useragent.analyze.UserAgentStringMatchMaker
All Implemented Interfaces:
Serializable, MatchMaker, AnalyzerConfigHolder

public class UserAgentStringMatchMaker extends Object implements MatchMaker, AnalyzerConfigHolder, Serializable
See Also:
  • Field Details

  • Constructor Details

    • UserAgentStringMatchMaker

      public UserAgentStringMatchMaker(AnalyzerConfig analyzerConfig, boolean showMatcherStats, boolean delayInitialization)
  • Method Details

    • getAllMatchers

      public List<Matcher> getAllMatchers()
    • getTouchedMatchers

      public MatcherList getTouchedMatchers()
    • getConfig

      @Nonnull public AnalyzerConfig getConfig()
      Description copied from interface: AnalyzerConfigHolder
      Obtain the config for this analyzer.
      Specified by:
      getConfig in interface AnalyzerConfigHolder
      Returns:
      The instance of the config used by this analyzer.
    • configureKryo

      public static void configureKryo(Object kryo)
      This is used to configure the provided Kryo instance if Kryo serialization is desired. The expected type here is Object because otherwise the Kryo library becomes a mandatory dependency on any project that uses Yauaa.
      Parameters:
      kryo - The instance of com.esotericsoftware.kryo.Kryo that needs to be configured.
    • destroy

      public void destroy()
      In some cases it was found that simply dereferencing the instance and letting the GC clean it all up was "too hard". To assist in these kinds of problem cases this method will wipe the internal data structures as much as possible. After calling this method this instance becomes unusable and cannot be 'repaired'. Normal applications will never need this. Simply dereferencing the analyzer will clean everything, no memory leaks (that we know of).
    • loadResources

      public void loadResources(String resourceString)
    • loadResources

      public void loadResources(String resourceString, boolean showLoadMessages, boolean optionalResources)
    • finalizeLoadingRules

      public void finalizeLoadingRules()
    • initializeMatchers

      public void initializeMatchers()
    • getAllPossibleFieldNames

      public Set<String> getAllPossibleFieldNames()
    • getAllPossibleFieldNamesSorted

      public List<String> getAllPossibleFieldNamesSorted()
    • lookingForRange

      public void lookingForRange(String treeName, WordRangeVisitor.Range range)
      Specified by:
      lookingForRange in interface MatchMaker
    • firstCharactersForPrefixHashLength

      public static int firstCharactersForPrefixHashLength(String input, int maxChars)
    • firstCharactersForPrefixHash

      public static String firstCharactersForPrefixHash(String input, int maxChars)
    • informMeAboutPrefix

      public void informMeAboutPrefix(MatcherAction matcherAction, String treeName, String prefix)
      Specified by:
      informMeAboutPrefix in interface MatchMaker
    • getRequiredPrefixLengths

      public Set<Integer> getRequiredPrefixLengths(String treeName)
      Specified by:
      getRequiredPrefixLengths in interface MatchMaker
    • informMeAbout

      public void informMeAbout(MatcherAction matcherAction, String keyPattern)
      Specified by:
      informMeAbout in interface MatchMaker
    • setVerbose

      public void setVerbose(boolean newVerbose)
    • getUserAgentMaxLength

      public int getUserAgentMaxLength()
      Specified by:
      getUserAgentMaxLength in interface AnalyzerConfigHolder
    • receivedInput

      public void receivedInput(Matcher matcher)
      Specified by:
      receivedInput in interface MatchMaker
    • reset

      public void reset()
      Resets the state of the Analyzer to the default state.
    • parse

      Parses and analyzes the useragent string provided in the MutableUserAgent instance. NOTE: This method is internally synchronized because the way the analyzer works is not reentrant.
      Parameters:
      userAgent - The MutableUserAgent instance that is to be parsed and that gets all results
      Returns:
      An ImmutableUserAgent copy of the results that is suitable for further usage and caching.
    • isWantedField

      public boolean isWantedField(String fieldName)
    • getWantedFieldNames

      public Set<String> getWantedFieldNames()
    • setFieldCalculators

      public void setFieldCalculators(List<FieldCalculator> newFieldCalculators)
    • hardCodedPostProcessing

      public UserAgent.MutableUserAgent hardCodedPostProcessing(UserAgent.MutableUserAgent userAgent)
    • getRequiredInformRanges

      public Set<WordRangeVisitor.Range> getRequiredInformRanges(String treeName)
      Specified by:
      getRequiredInformRanges in interface MatchMaker
    • inform

      public void inform(String key, String value, org.antlr.v4.runtime.tree.ParseTree ctx)
      Specified by:
      inform in interface MatchMaker
    • verifyCalculatorDependencyOrdering

      protected void verifyCalculatorDependencyOrdering()
    • getMatches

      public List<MatchesList.Match> getMatches()
      This function is used only for analyzing which patterns that could possibly be relevant were actually relevant for the matcher actions.
      Returns:
      The list of Matches that were possibly relevant.
    • getUsedMatches

      public List<MatchesList.Match> getUsedMatches(UserAgent.MutableUserAgent userAgent)
    • toString

      public String toString()
      Overrides:
      toString in class Object