Class UriPattern
- java.lang.Object
-
- com.yahoo.jdisc.application.UriPattern
-
- All Implemented Interfaces:
java.lang.Comparable<UriPattern>
public class UriPattern extends java.lang.Object implements java.lang.Comparable<UriPattern>
This class holds a regular expression designed so that it only matches certain
URI
s. The constructor of this class accepts a simplified pattern string, and turns that into something that can be used to quickly match against URIs. This class also implementsComparable
in such a way that stricter patterns order before looser patterns.Here are some examples of ordering:
http://host/path
evaluated before*://host/path
http://host/path
evaluated beforehttp://*/path
http://a.host/path
evaluated beforehttp://*.host/path
http://*.host/path
evaluated beforehttp://host/path
http://host.a/path
evaluated beforehttp://host.*/path
http://host.*/path
evaluated beforehttp://host/path
http://host:80/path
evaluated beforehttp://host:*/path
http://host/path
evaluated beforehttp://host/*
http://host/path/*
evaluated beforehttp://host/path
- Author:
- Simon Thoresen Hult, bjorncs
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UriPattern.Match
This class holds the result of amatch(URI)
operation.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PRIORITY
-
Constructor Summary
Constructors Constructor Description UriPattern(java.lang.String uri)
Creates a new instance of this class that represents the given pattern string, with a priority of0
.UriPattern(java.lang.String uri, int priority)
Creates a new instance of this class that represents the given pattern string, with the given priority.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(UriPattern rhs)
boolean
equals(java.lang.Object obj)
int
hashCode()
UriPattern.Match
match(java.net.URI uri)
Attempts to match the givenURI
to this pattern.java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UriPattern
public UriPattern(java.lang.String uri)
Creates a new instance of this class that represents the given pattern string, with a priority of
0
. The input string must be on the form<scheme>://<host>[:<port>]<path>
, where '*' can be used as a wildcard character at any position.- Parameters:
uri
- The pattern to parse.- Throws:
java.lang.IllegalArgumentException
- If the pattern could not be parsed.
-
UriPattern
public UriPattern(java.lang.String uri, int priority)
Creates a new instance of this class that represents the given pattern string, with the given priority. The input string must be on the form
<scheme>://<host>[:<port>]<path>
, where '*' can be used as a wildcard character at any position.- Parameters:
uri
- The pattern to parse.priority
- The priority of this pattern.- Throws:
java.lang.IllegalArgumentException
- If the pattern could not be parsed.
-
-
Method Detail
-
match
public UriPattern.Match match(java.net.URI uri)
Attempts to match the given
URI
to this pattern. Note that only the scheme, host, port, and path components of the URI are used. Any query or fragment part is simply ignored.- Parameters:
uri
- The URI to match.- Returns:
- A
UriPattern.Match
object describing the match found, or null if not found.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
compareTo
public int compareTo(UriPattern rhs)
- Specified by:
compareTo
in interfacejava.lang.Comparable<UriPattern>
-
-