MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / relativize

Method relativize

vm/JavaAPI/src/java/net/URI.java:786–811  ·  view source on GitHub ↗

Create a relative URI object against this URI, given the uri parameter. @param uri @return @see http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#relativize%28java.net.URI%29

(URI uri)

Source from the content-addressed store, hash-verified

784 * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#relativize%28java.net.URI%29">http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#relativize%28java.net.URI%29</a>
785 */
786 public URI relativize(URI uri) {
787 if (isOpaque() || uri.isOpaque()) {
788 return uri;
789 }
790 if (getScheme() == null || uri.getScheme() == null || getScheme().equals(uri.getScheme()) == false) {
791 return uri;
792 }
793 String thisAuthority = null;
794 String thatAuthority = null;
795 String thisPath = null;
796 String thatPath = null;
797 if ((thisAuthority = getAuthority()) == null || (thatAuthority = uri.getAuthority()) == null
798 || thisAuthority.equals(thatAuthority) == false) {
799 return uri;
800 }
801 if ((thisPath = getPath()) == null || (thatPath = uri.getPath()) == null
802 || thatPath.startsWith(thisPath + PATH_SEPARATOR) == false) {
803 return uri;
804 }
805 try {
806 return new URI(null, null, thatPath.substring(thisPath.length() + 1), uri.getQuery(), uri.getFragment());
807 } catch (URISyntaxException e) {
808 // Since the two URIs are pre-validated, we should never get here.
809 throw new IllegalArgumentException(e.getMessage());
810 }
811 }
812
813 /**
814 * Resolve a relative URI by merging it with this URI.

Callers 4

copyDirectoryMethod · 0.45
collectResourcesMethod · 0.45
walkAndZipMethod · 0.45

Calls 12

isOpaqueMethod · 0.95
getSchemeMethod · 0.95
getAuthorityMethod · 0.95
equalsMethod · 0.95
getPathMethod · 0.95
startsWithMethod · 0.95
substringMethod · 0.95
lengthMethod · 0.95
equalsMethod · 0.65
getQueryMethod · 0.65
getMessageMethod · 0.65
getFragmentMethod · 0.45

Tested by 1

copyDirectoryMethod · 0.36