Java Reference
In-Depth Information
After they've executed, resolved contains the absolute URI http://www.example.com/
images/logo.png .
If the invoking URI does not contain an absolute URI itself, the resolve() method
resolves as much of the URI as it can and returns a new relative URI object as a result.
For example, take these three statements:
URI top = new URI ( "javafaq/books/" );
URI resolved = top . resolve ( "jnp3/examples/07/index.html" );
After they've executed, resolved now contains the relative URI javafaq/books/jnp3/
examples/07/index.html with no scheme or authority.
It's also possible to reverse this procedure; that is, to go from an absolute URI to a relative
one. The relativize() method creates a new URI object from the uri argument that
is relative to the invoking URI . The argument is not changed. For example:
URI absolute = new URI ( "http://www.example.com/images/logo.png" );
URI top = new URI ( "http://www.example.com/" );
URI relative = top . relativize ( absolute );
The URI object relative now contains the relative URI images/logo.png .
Equality and Comparison
URIs are tested for equality pretty much as you'd expect. It's not quite direct string
comparison. Equal URIs must both either be hierarchical or opaque. The scheme and
authority parts are compared without considering case. That is, http and HTTP are the
same scheme, and www.example.com is the same authority as www.EXAMPLE.com .
The rest of the URI is case sensitive, except for hexadecimal digits used to escape illegal
characters. Escapes are not decoded before comparing. http://www.example.com/A and
http://www.example.com/%41 are unequal URIs.
The hashCode() method is consistent with equals. Equal URIs do have the same hash
code and unequal URIs are fairly unlikely to share the same hash code.
URI implements Comparable , and thus URIs can be ordered. The ordering is based on
string comparison of the individual parts, in this sequence:
1. If the schemes are different, the schemes are compared, without considering case.
2. Otherwise, if the schemes are the same, a hierarchical URI is considered to be less
than an opaque URI with the same scheme.
3. If both URIs are opaque URIs, they're ordered according to their scheme-specific
parts.
4. If both the scheme and the opaque scheme-specific parts are equal, the URIs are
compared by their fragments.
Search WWH ::




Custom Search