Interface URIMatcher

All Superinterfaces:
Comparable<URIMatcher>

public interface URIMatcher extends Comparable<URIMatcher>

An engine that performs match operations on a URI by interpreting a URI pattern.

A URI matcher is created from a URI pattern by invoking the pattern's URIPattern.matcher(String) method. Once created a matcher can be used to determine whether the input URI matches against the URI pattern and extract parameters from the input URI assuming parameters have been specified when building the URI pattern.

For instance the following shows how to match an absolute path against /book/{id} pattern and extract the id path parameter:


 URIPattern pathPattern = URIs.uri("/book/{id}", URIs.Option.PARAMETERIZED).buildPathPattern();
 
 URIMatcher matcher = pathPattern.matcher("/book/123");
 if (matcher.matches()) {
     String id = matcher.getParameterValue("id").get();
 }
 
Since:
1.0
Author:
Jeremy Kuhn
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the underlying JDK matcher.
    Returns a map containing the parameters extracted from the input URI.
    Return the value of the parameter with the specified name extracted from the input URI.
    boolean
    Determines whether the input URI matches against the URI pattern.

    Methods inherited from interface java.lang.Comparable

    compareTo
  • Method Details

    • matches

      boolean matches()

      Determines whether the input URI matches against the URI pattern.

      If the match succeeds then parameters if any can be obtained via getParameterValue and getParameters methods.

      Returns:
      true if the input URI matches, false otherwise
    • getMatcher

      Matcher getMatcher()

      Return the underlying JDK matcher.

      Returns:
      a matcher
    • getParameterValue

      Optional<String> getParameterValue(String name)

      Return the value of the parameter with the specified name extracted from the input URI.

      The matches method must be called first to extract parameters assuming the input URI matches the pattern.

      Parameters:
      name - the parameter name
      Returns:
      an optional providing the value
    • getParameters

      Map<String,String> getParameters()

      Returns a map containing the parameters extracted from the input URI.

      The matches method must be called first to extract parameters assuming the input URI matches the pattern.

      Returns:
      a map of parameters