Class ExpandedIdsMatcher

java.lang.Object
org.elasticsearch.xpack.core.action.util.ExpandedIdsMatcher

public final class ExpandedIdsMatcher extends Object
Class for tracking the set of Ids returned from some function a satisfy the required Ids as defined by an expression that may contain wildcards. For example, given a set of Ids ["foo-1", "foo-2", "bar-1", bar-2"]:
  • The expression foo* would be satisfied by foo-1 and foo-2
  • The expression bar-1 would be satisfied by bar-1
  • The expression bar-1,car-1 would leave car-1 unmatched
  • The expression * would be satisfied by anything or nothing depending on the value of allowNoMatchForWildcards
  • Constructor Details

    • ExpandedIdsMatcher

      public ExpandedIdsMatcher(String[] tokens, boolean allowNoMatchForWildcards)
      Generate the list of required matches from the expressions in tokens and initialize.
      Parameters:
      tokens - List of expressions that may be wildcards or full Ids
      allowNoMatchForWildcards - If true then it is not required for wildcard expressions to match an Id meaning they are not returned in the list of required matches
    • ExpandedIdsMatcher

      public ExpandedIdsMatcher(String expression, boolean allowNoMatchForWildcards)
      Generate the list of required matches from the expression and initialize.
      Parameters:
      expression - Expression that will be tokenized into a set of wildcards or full Ids
      allowNoMatchForWildcards - If true then it is not required for wildcard expressions to match an Id meaning they are not returned in the list of required matches
  • Method Details

    • tokenizeExpression

      public static String[] tokenizeExpression(String expression)
      Split expression into tokens separated by a ','
      Parameters:
      expression - Expression containing zero or more ','s
      Returns:
      Array of tokens
    • idMatches

      public boolean idMatches(String id)
      Test whether an ID matches any of the expressions. Unlike filterMatchedIds(java.util.Collection<java.lang.String>) this does not modify the state of the matcher.
      Parameters:
      id - ID to test.
      Returns:
      Does the ID match one or more of the patterns in the expression?
    • filterMatchedIds

      public void filterMatchedIds(Collection<String> ids)
      For each requiredMatchers check there is an element present in ids that matches. Once a match is made the matcher is removed from requiredMatchers.
    • hasUnmatchedIds

      public boolean hasUnmatchedIds()
    • unmatchedIds

      public List<String> unmatchedIds()
    • unmatchedIdsString

      public String unmatchedIdsString()
    • isOnlyExact

      public boolean isOnlyExact()
      Whether ids are based on exact matchers or at least one contains a wildcard.
      Returns:
      true if only exact matches, false if at least one id contains a wildcard