java.lang.Object
org.elasticsearch.xpack.core.ml.utils.NameResolver

public abstract class NameResolver extends Object
Expands an expression into the set of matching names. It optionally supports aliases to the name set.
  • Constructor Details

  • Method Details

    • expand

      public SortedSet<String> expand(String expression, boolean allowNoMatch)
      Expands an expression into the set of matching names. For example, given a set of names ["foo-1", "foo-2", "bar-1", bar-2"], expressions resolve as follows:
      • "foo-1" : ["foo-1"]
      • "bar-1" : ["bar-1"]
      • "foo-*" : ["foo-1", "foo-2"]
      • "*-1" : ["bar-1", "foo-1"]
      • "*" : ["bar-1", "bar-2", "foo-1", "foo-2"]
      • "_all" : ["bar-1", "bar-2", "foo-1", "foo-2"]
      Parameters:
      expression - the expression to resolve
      allowNoMatch - if false, an error is thrown when no name matches the expression. This only applies to wild card expressions, if expression is not a wildcard then setting this true will not suppress the exception
      Returns:
      the sorted set of matching names
    • expand

      public SortedSet<String> expand(String expression, boolean allowNoMatch, Optional<String> tokenizationDelimiter)
      Expands an expression into the set of matching names. If a tokenization delimiter is provided, then the expression is first tokenized and then each token is expanded. For example, given a set of names ["foo-1", "foo-2", "bar-1", bar-2"] and comma as the delimiter expressions resolve as follows:
      • "foo-1" : ["foo-1"]
      • "bar-1" : ["bar-1"]
      • "foo-1,foo-2" : ["foo-1", "foo-2"]
      • "foo-*" : ["foo-1", "foo-2"]
      • "*-1" : ["bar-1", "foo-1"]
      • "*" : ["bar-1", "bar-2", "foo-1", "foo-2"]
      • "_all" : ["bar-1", "bar-2", "foo-1", "foo-2"]
      Parameters:
      expression - the expression to resolve
      allowNoMatch - if false, an error is thrown when no name matches the expression. This only applies to wild card expressions, if expression is not a wildcard then setting this true will not suppress the exception
      tokenizationDelimiter - An optional delimiter to tokenize the expression on
      Returns:
      the sorted set of matching names
    • keys

      protected abstract Set<String> keys()
      Returns:
      the set of registered keys
    • nameSet

      protected abstract Set<String> nameSet()
      Returns:
      the set of all names
    • lookup

      protected abstract List<String> lookup(String key)
      Looks up a key and returns the matching names.
      Parameters:
      key - the key to look up
      Returns:
      a list of the matching names or null when no matching names exist
    • newUnaliased

      public static NameResolver newUnaliased(Set<String> nameSet, Function<String,ResourceNotFoundException> notFoundExceptionSupplier)
      Creates a NameResolver that has no aliases
      Parameters:
      nameSet - the set of all names
      notFoundExceptionSupplier - a supplier of ResourceNotFoundException to be used when an expression matches no name
      Returns:
      the unaliased NameResolver