Class ProviderSpec

java.lang.Object
opennlp.tools.util.ext.ProviderSpec

public final class ProviderSpec extends Object
Describes what a Provider should create: an optional location, such as a model file, and string options. Instances are immutable.
Since:
3.0.0
See Also:
  • Method Details

    • empty

      public static ProviderSpec empty()
      Returns:
      A spec without location and options. Never null.
    • of

      public static ProviderSpec of(Map<String,String> options)
      Creates a spec with options and without location.
      Parameters:
      options - The options. Must not be null, an option name must not be null or blank and an option value must not be null.
      Returns:
      The spec. Never null.
      Throws:
      IllegalArgumentException - Thrown if options is invalid.
    • of

      public static ProviderSpec of(URI location)
      Creates a spec with a location and without options.
      Parameters:
      location - The absolute location. Must not be null.
      Returns:
      The spec. Never null.
      Throws:
      IllegalArgumentException - Thrown if location is null or not absolute.
    • of

      public static ProviderSpec of(URI location, Map<String,String> options)
      Creates a spec with a location and options.
      Parameters:
      location - The absolute location, which is taken as it is, unlike the location of of(Path, Map). Must not be null.
      options - The options. Must not be null, an option name must not be null or blank and an option value must not be null.
      Returns:
      The spec. Never null.
      Throws:
      IllegalArgumentException - Thrown if location is null or not absolute, or if options is invalid.
    • of

      public static ProviderSpec of(Path location)
      Creates a spec for a file or directory without options, see of(Path, Map).
      Parameters:
      location - The file or directory. Must not be null.
      Returns:
      The spec. Never null.
      Throws:
      IllegalArgumentException - Thrown if location is null.
    • of

      public static ProviderSpec of(Path location, Map<String,String> options)
      Creates a spec for a file or directory with options. A relative path is resolved against the working directory of the running process when the spec is created, so a spec that is kept in a static field must not be created from a relative path. The file system is not read, so the location of a directory carries no trailing separator and a path holding .. is kept as it is.
      Parameters:
      location - The file or directory. Must not be null.
      options - The options. Must not be null, an option name must not be null or blank and an option value must not be null.
      Returns:
      The spec. Never null.
      Throws:
      IllegalArgumentException - Thrown if location is null, or if options is invalid.
    • location

      public Optional<URI> location()
      Returns:
      The location, or Optional.empty() if this spec has none.
    • path

      public Optional<Path> path()
      Returns:
      The location as a path, or Optional.empty() if this spec has no location or the location is not a hierarchical file URI of the default file system.
    • options

      public Map<String,String> options()
      Returns:
      The options in insertion order. Unmodifiable and never null.
    • option

      public String option(String key, String defaultValue)
      Reads an option.
      Parameters:
      key - The option name. Must not be null.
      defaultValue - The value to return if the option is absent. May be null.
      Returns:
      The option value, or defaultValue.
      Throws:
      IllegalArgumentException - Thrown if key is null.
    • hasOnlyOptions

      public boolean hasOnlyOptions(String... names)
      Checks whether every option of this spec has one of the given names.
      Parameters:
      names - The accepted option names. Must not be null or contain a null element.
      Returns:
      true if this spec has no option with another name.
      Throws:
      IllegalArgumentException - Thrown if names is null or contains a null element.
    • locationEndsWith

      public boolean locationEndsWith(String suffix)
      Checks whether the last path segment of the location ends with a suffix, ignoring case. A query and a fragment are not part of the comparison. For an opaque URI, such as jar:file:/models.jar!/model.onnx, the scheme-specific part is used as path. This is a convenience for routing a request to a provider, not a validation of the location.
      Parameters:
      suffix - The suffix, for example .onnx. Must not be null or empty.
      Returns:
      true if this spec has a location and its last path segment ends with suffix.
      Throws:
      IllegalArgumentException - Thrown if suffix is null or empty.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      The option values and the user info, query and fragment of the location are omitted, as they may hold credentials.
      Overrides:
      toString in class Object